home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / u_man / cat1 / perlguts.z / perlguts
Encoding:
Text File  |  1998-10-30  |  135.1 KB  |  4,027 lines

  1.  
  2.  
  3.  
  4. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      perlguts - Perl's Internal Functions
  10.  
  11. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  12.      This document attempts to describe some of the internal functions of the
  13.      Perl executable.  It is far from complete and probably contains many
  14.      errors.  Please refer any questions or comments to the author below.
  15.  
  16. VVVVaaaarrrriiiiaaaabbbblllleeeessss
  17.      DDDDaaaattttaaaattttyyyyppppeeeessss
  18.  
  19.      Perl has three typedefs that handle Perl's three main data types:
  20.  
  21.          SV  Scalar Value
  22.          AV  Array Value
  23.          HV  Hash Value
  24.  
  25.      Each typedef has specific routines that manipulate the various data
  26.      types.
  27.  
  28.      WWWWhhhhaaaatttt iiiissss aaaannnn """"IIIIVVVV""""????
  29.  
  30.      Perl uses a special typedef IV which is a simple integer type that is
  31.      guaranteed to be large enough to hold a pointer (as well as an integer).
  32.  
  33.      Perl also uses two special typedefs, I32 and I16, which will always be at
  34.      least 32-bits and 16-bits long, respectively.
  35.  
  36.      WWWWoooorrrrkkkkiiiinnnngggg wwwwiiiitttthhhh SSSSVVVVssss
  37.  
  38.      An SV can be created and loaded with one command.  There are four types
  39.      of values that can be loaded: an integer value (IV), a double (NV), a
  40.      string, (PV), and another scalar (SV).
  41.  
  42.      The five routines are:
  43.  
  44.          SV*  newSViv(IV);
  45.          SV*  newSVnv(double);
  46.          SV*  newSVpv(char*, int);
  47.          SV*  newSVpvf(const char*, ...);
  48.          SV*  newSVsv(SV*);
  49.  
  50.      To change the value of an *already-existing* SV, there are six routines:
  51.  
  52.          void  sv_setiv(SV*, IV);
  53.          void  sv_setnv(SV*, double);
  54.          void  sv_setpv(SV*, char*);
  55.          void  sv_setpvn(SV*, char*, int)
  56.          void  sv_setpvf(SV*, const char*, ...);
  57.          void  sv_setsv(SV*, SV*);
  58.  
  59.      Notice that you can choose to specify the length of the string to be
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  71.  
  72.  
  73.  
  74.      assigned by using sv_setpvn or newSVpv, or you may allow Perl to
  75.      calculate the length by using sv_setpv or by specifying 0 as the second
  76.      argument to newSVpv.  Be warned, though, that Perl will determine the
  77.      string's length by using strlen, which depends on the string terminating
  78.      with a NUL character.  The arguments of sv_setpvf are processed like
  79.      sprintf, and the formatted output becomes the value.
  80.  
  81.      All SVs that will contain strings should, but need not, be terminated
  82.      with a NUL character.  If it is not NUL-terminated there is a risk of
  83.      core dumps and corruptions from code which passes the string to C
  84.      functions or system calls which expect a NUL-terminated string.  Perl's
  85.      own functions typically add a trailing NUL for this reason.
  86.      Nevertheless, you should be very careful when you pass a string stored in
  87.      an SV to a C function or system call.
  88.  
  89.      To access the actual value that an SV points to, you can use the macros:
  90.  
  91.          SvIV(SV*)
  92.          SvNV(SV*)
  93.          SvPV(SV*, STRLEN len)
  94.  
  95.      which will automatically coerce the actual scalar type into an IV,
  96.      double, or string.
  97.  
  98.      In the SvPV macro, the length of the string returned is placed into the
  99.      variable len (this is a macro, so you do _n_o_t use &len).  If you do not
  100.      care what the length of the data is, use the global variable na.
  101.      Remember, however, that Perl allows arbitrary strings of data that may
  102.      both contain NULs and might not be terminated by a NUL.
  103.  
  104.      If you want to know if the scalar value is TRUE, you can use:
  105.  
  106.          SvTRUE(SV*)
  107.  
  108.      Although Perl will automatically grow strings for you, if you need to
  109.      force Perl to allocate more memory for your SV, you can use the macro
  110.  
  111.          SvGROW(SV*, STRLEN newlen)
  112.  
  113.      which will determine if more memory needs to be allocated.  If so, it
  114.      will call the function sv_grow.  Note that SvGROW can only increase, not
  115.      decrease, the allocated memory of an SV and that it does not
  116.      automatically add a byte for the a trailing NUL (perl's own string
  117.      functions typically do SvGROW(sv, len + 1)).
  118.  
  119.      If you have an SV and want to know what kind of data Perl thinks is
  120.      stored in it, you can use the following macros to check the type of SV
  121.      you have.
  122.  
  123.          SvIOK(SV*)
  124.          SvNOK(SV*)
  125.          SvPOK(SV*)
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  137.  
  138.  
  139.  
  140.      You can get and set the current length of the string stored in an SV with
  141.      the following macros:
  142.  
  143.          SvCUR(SV*)
  144.          SvCUR_set(SV*, I32 val)
  145.  
  146.      You can also get a pointer to the end of the string stored in the SV with
  147.      the macro:
  148.  
  149.          SvEND(SV*)
  150.  
  151.      But note that these last three macros are valid only if SvPOK() is true.
  152.  
  153.      If you want to append something to the end of string stored in an SV*,
  154.      you can use the following functions:
  155.  
  156.          void  sv_catpv(SV*, char*);
  157.          void  sv_catpvn(SV*, char*, int);
  158.          void  sv_catpvf(SV*, const char*, ...);
  159.          void  sv_catsv(SV*, SV*);
  160.  
  161.      The first function calculates the length of the string to be appended by
  162.      using strlen.  In the second, you specify the length of the string
  163.      yourself.  The third function processes its arguments like sprintf and
  164.      appends the formatted output.  The fourth function extends the string
  165.      stored in the first SV with the string stored in the second SV.  It also
  166.      forces the second SV to be interpreted as a string.
  167.  
  168.      If you know the name of a scalar variable, you can get a pointer to its
  169.      SV by using the following:
  170.  
  171.          SV*  perl_get_sv("package::varname", FALSE);
  172.  
  173.      This returns NULL if the variable does not exist.
  174.  
  175.      If you want to know if this variable (or any other SV) is actually
  176.      defined, you can call:
  177.  
  178.          SvOK(SV*)
  179.  
  180.      The scalar undef value is stored in an SV instance called sv_undef.  Its
  181.      address can be used whenever an SV* is needed.
  182.  
  183.      There are also the two values sv_yes and sv_no, which contain Boolean
  184.      TRUE and FALSE values, respectively.  Like sv_undef, their addresses can
  185.      be used whenever an SV* is needed.
  186.  
  187.      Do not be fooled into thinking that (SV *) 0 is the same as &sv_undef.
  188.      Take this code:
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  203.  
  204.  
  205.  
  206.          SV* sv = (SV*) 0;
  207.          if (I-am-to-return-a-real-value) {
  208.                  sv = sv_2mortal(newSViv(42));
  209.          }
  210.          sv_setsv(ST(0), sv);
  211.  
  212.      This code tries to return a new SV (which contains the value 42) if it
  213.      should return a real value, or undef otherwise.  Instead it has returned
  214.      a NULL pointer which, somewhere down the line, will cause a segmentation
  215.      violation, bus error, or just weird results.  Change the zero to
  216.      &sv_undef in the first line and all will be well.
  217.  
  218.      To free an SV that you've created, call SvREFCNT_dec(SV*).  Normally this
  219.      call is not necessary (see the section on _R_e_f_e_r_e_n_c_e _C_o_u_n_t_s _a_n_d
  220.      _M_o_r_t_a_l_i_t_y).
  221.  
  222.      WWWWhhhhaaaatttt''''ssss RRRReeeeaaaallllllllyyyy SSSSttttoooorrrreeeedddd iiiinnnn aaaannnn SSSSVVVV????
  223.  
  224.      Recall that the usual method of determining the type of scalar you have
  225.      is to use Sv*OK macros.  Because a scalar can be both a number and a
  226.      string, usually these macros will always return TRUE and calling the Sv*V
  227.      macros will do the appropriate conversion of string to integer/double or
  228.      integer/double to string.
  229.  
  230.      If you _r_e_a_l_l_y need to know if you have an integer, double, or string
  231.      pointer in an SV, you can use the following three macros instead:
  232.  
  233.          SvIOKp(SV*)
  234.          SvNOKp(SV*)
  235.          SvPOKp(SV*)
  236.  
  237.      These will tell you if you truly have an integer, double, or string
  238.      pointer stored in your SV.  The "p" stands for private.
  239.  
  240.      In general, though, it's best to use the Sv*V macros.
  241.  
  242.      WWWWoooorrrrkkkkiiiinnnngggg wwwwiiiitttthhhh AAAAVVVVssss
  243.  
  244.      There are two ways to create and load an AV.  The first method creates an
  245.      empty AV:
  246.  
  247.          AV*  newAV();
  248.  
  249.      The second method both creates the AV and initially populates it with
  250.      SVs:
  251.  
  252.          AV*  av_make(I32 num, SV **ptr);
  253.  
  254.      The second argument points to an array containing num SV*'s.  Once the AV
  255.      has been created, the SVs can be destroyed, if so desired.
  256.  
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  269.  
  270.  
  271.  
  272.      Once the AV has been created, the following operations are possible on
  273.      AVs:
  274.  
  275.          void  av_push(AV*, SV*);
  276.          SV*   av_pop(AV*);
  277.          SV*   av_shift(AV*);
  278.          void  av_unshift(AV*, I32 num);
  279.  
  280.      These should be familiar operations, with the exception of av_unshift.
  281.      This routine adds num elements at the front of the array with the undef
  282.      value.  You must then use av_store (described below) to assign values to
  283.      these new elements.
  284.  
  285.      Here are some other functions:
  286.  
  287.          I32   av_len(AV*);
  288.          SV**  av_fetch(AV*, I32 key, I32 lval);
  289.          SV**  av_store(AV*, I32 key, SV* val);
  290.  
  291.      The av_len function returns the highest index value in array (just like
  292.      $#array in Perl).  If the array is empty, -1 is returned.  The av_fetch
  293.      function returns the value at index key, but if lval is non-zero, then
  294.      av_fetch will store an undef value at that index.  The av_store function
  295.      stores the value val at index key, and does not increment the reference
  296.      count of val.  Thus the caller is responsible for taking care of that,
  297.      and if av_store returns NULL, the caller will have to decrement the
  298.      reference count to avoid a memory leak.  Note that av_fetch and av_store
  299.      both return SV**'s, not SV*'s as their return value.
  300.  
  301.          void  av_clear(AV*);
  302.          void  av_undef(AV*);
  303.          void  av_extend(AV*, I32 key);
  304.  
  305.      The av_clear function deletes all the elements in the AV* array, but does
  306.      not actually delete the array itself.  The av_undef function will delete
  307.      all the elements in the array plus the array itself.  The av_extend
  308.      function extends the array so that it contains key elements.  If key is
  309.      less than the current length of the array, then nothing is done.
  310.  
  311.      If you know the name of an array variable, you can get a pointer to its
  312.      AV by using the following:
  313.  
  314.          AV*  perl_get_av("package::varname", FALSE);
  315.  
  316.      This returns NULL if the variable does not exist.
  317.  
  318.      See the section on _U_n_d_e_r_s_t_a_n_d_i_n_g _t_h_e _M_a_g_i_c _o_f _T_i_e_d _H_a_s_h_e_s _a_n_d _A_r_r_a_y_s for
  319.      more information on how to use the array access functions on tied arrays.
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.                                                                         PPPPaaaaggggeeee 5555
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  335.  
  336.  
  337.  
  338.      WWWWoooorrrrkkkkiiiinnnngggg wwwwiiiitttthhhh HHHHVVVVssss
  339.  
  340.      To create an HV, you use the following routine:
  341.  
  342.          HV*  newHV();
  343.  
  344.      Once the HV has been created, the following operations are possible on
  345.      HVs:
  346.  
  347.          SV**  hv_store(HV*, char* key, U32 klen, SV* val, U32 hash);
  348.          SV**  hv_fetch(HV*, char* key, U32 klen, I32 lval);
  349.  
  350.      The klen parameter is the length of the key being passed in (Note that
  351.      you cannot pass 0 in as a value of klen to tell Perl to measure the
  352.      length of the key).  The val argument contains the SV pointer to the
  353.      scalar being stored, and hash is the precomputed hash value (zero if you
  354.      want hv_store to calculate it for you).  The lval parameter indicates
  355.      whether this fetch is actually a part of a store operation, in which case
  356.      a new undefined value will be added to the HV with the supplied key and
  357.      hv_fetch will return as if the value had already existed.
  358.  
  359.      Remember that hv_store and hv_fetch return SV**'s and not just SV*.  To
  360.      access the scalar value, you must first dereference the return value.
  361.      However, you should check to make sure that the return value is not NULL
  362.      before dereferencing it.
  363.  
  364.      These two functions check if a hash table entry exists, and deletes it.
  365.  
  366.          bool  hv_exists(HV*, char* key, U32 klen);
  367.          SV*   hv_delete(HV*, char* key, U32 klen, I32 flags);
  368.  
  369.      If flags does not include the G_DISCARD flag then hv_delete will create
  370.      and return a mortal copy of the deleted value.
  371.  
  372.      And more miscellaneous functions:
  373.  
  374.          void   hv_clear(HV*);
  375.          void   hv_undef(HV*);
  376.  
  377.      Like their AV counterparts, hv_clear deletes all the entries in the hash
  378.      table but does not actually delete the hash table.  The hv_undef deletes
  379.      both the entries and the hash table itself.
  380.  
  381.      Perl keeps the actual data in linked list of structures with a typedef of
  382.      HE.  These contain the actual key and value pointers (plus extra
  383.      administrative overhead).  The key is a string pointer; the value is an
  384.      SV*.  However, once you have an HE*, to get the actual key and value, use
  385.      the routines specified below.
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.                                                                         PPPPaaaaggggeeee 6666
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  401.  
  402.  
  403.  
  404.          I32    hv_iterinit(HV*);
  405.                  /* Prepares starting point to traverse hash table */
  406.          HE*    hv_iternext(HV*);
  407.                  /* Get the next entry, and return a pointer to a
  408.                     structure that has both the key and value */
  409.          char*  hv_iterkey(HE* entry, I32* retlen);
  410.                  /* Get the key from an HE structure and also return
  411.                     the length of the key string */
  412.          SV*    hv_iterval(HV*, HE* entry);
  413.                  /* Return a SV pointer to the value of the HE
  414.                     structure */
  415.          SV*    hv_iternextsv(HV*, char** key, I32* retlen);
  416.                  /* This convenience routine combines hv_iternext,
  417.                     hv_iterkey, and hv_iterval.  The key and retlen
  418.                     arguments are return values for the key and its
  419.                     length.  The value is returned in the SV* argument */
  420.  
  421.      If you know the name of a hash variable, you can get a pointer to its HV
  422.      by using the following:
  423.  
  424.          HV*  perl_get_hv("package::varname", FALSE);
  425.  
  426.      This returns NULL if the variable does not exist.
  427.  
  428.      The hash algorithm is defined in the PERL_HASH(hash, key, klen) macro:
  429.  
  430.          i = klen;
  431.          hash = 0;
  432.          s = key;
  433.          while (i--)
  434.              hash = hash * 33 + *s++;
  435.  
  436.      See the section on _U_n_d_e_r_s_t_a_n_d_i_n_g _t_h_e _M_a_g_i_c _o_f _T_i_e_d _H_a_s_h_e_s _a_n_d _A_r_r_a_y_s for
  437.      more information on how to use the hash access functions on tied hashes.
  438.  
  439.      HHHHaaaasssshhhh AAAAPPPPIIII EEEExxxxtttteeeennnnssssiiiioooonnnnssss
  440.  
  441.      Beginning with version 5.004, the following functions are also supported:
  442.  
  443.          HE*     hv_fetch_ent  (HV* tb, SV* key, I32 lval, U32 hash);
  444.          HE*     hv_store_ent  (HV* tb, SV* key, SV* val, U32 hash);
  445.  
  446.          bool    hv_exists_ent (HV* tb, SV* key, U32 hash);
  447.          SV*     hv_delete_ent (HV* tb, SV* key, I32 flags, U32 hash);
  448.  
  449.          SV*     hv_iterkeysv  (HE* entry);
  450.  
  451.      Note that these functions take SV* keys, which simplifies writing of
  452.      extension code that deals with hash structures.  These functions also
  453.      allow passing of SV* keys to tie functions without forcing you to
  454.      stringify the keys (unlike the previous set of functions).
  455.  
  456.  
  457.  
  458.  
  459.                                                                         PPPPaaaaggggeeee 7777
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  467.  
  468.  
  469.  
  470.      They also return and accept whole hash entries (HE*), making their use
  471.      more efficient (since the hash number for a particular string doesn't
  472.      have to be recomputed every time).  See the section on _A_P_I _L_I_S_T_I_N_G later
  473.      in this document for detailed descriptions.
  474.  
  475.      The following macros must always be used to access the contents of hash
  476.      entries.  Note that the arguments to these macros must be simple
  477.      variables, since they may get evaluated more than once.  See the section
  478.      on _A_P_I _L_I_S_T_I_N_G later in this document for detailed descriptions of these
  479.      macros.
  480.  
  481.          HePV(HE* he, STRLEN len)
  482.          HeVAL(HE* he)
  483.          HeHASH(HE* he)
  484.          HeSVKEY(HE* he)
  485.          HeSVKEY_force(HE* he)
  486.          HeSVKEY_set(HE* he, SV* sv)
  487.  
  488.      These two lower level macros are defined, but must only be used when
  489.      dealing with keys that are not SV*s:
  490.  
  491.          HeKEY(HE* he)
  492.          HeKLEN(HE* he)
  493.  
  494.      Note that both hv_store and hv_store_ent do not increment the reference
  495.      count of the stored val, which is the caller's responsibility.  If these
  496.      functions return a NULL value, the caller will usually have to decrement
  497.      the reference count of val to avoid a memory leak.
  498.  
  499.      RRRReeeeffffeeeerrrreeeennnncccceeeessss
  500.  
  501.      References are a special type of scalar that point to other data types
  502.      (including references).
  503.  
  504.      To create a reference, use either of the following functions:
  505.  
  506.          SV* newRV_inc((SV*) thing);
  507.          SV* newRV_noinc((SV*) thing);
  508.  
  509.      The thing argument can be any of an SV*, AV*, or HV*.  The functions are
  510.      identical except that newRV_inc increments the reference count of the
  511.      thing, while newRV_noinc does not.  For historical reasons, newRV is a
  512.      synonym for newRV_inc.
  513.  
  514.      Once you have a reference, you can use the following macro to dereference
  515.      the reference:
  516.  
  517.          SvRV(SV*)
  518.  
  519.      then call the appropriate routines, casting the returned SV* to either an
  520.      AV* or HV*, if required.
  521.  
  522.  
  523.  
  524.  
  525.                                                                         PPPPaaaaggggeeee 8888
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  533.  
  534.  
  535.  
  536.      To determine if an SV is a reference, you can use the following macro:
  537.  
  538.          SvROK(SV*)
  539.  
  540.      To discover what type of value the reference refers to, use the following
  541.      macro and then check the return value.
  542.  
  543.          SvTYPE(SvRV(SV*))
  544.  
  545.      The most useful types that will be returned are:
  546.  
  547.          SVt_IV    Scalar
  548.          SVt_NV    Scalar
  549.          SVt_PV    Scalar
  550.          SVt_RV    Scalar
  551.          SVt_PVAV  Array
  552.          SVt_PVHV  Hash
  553.          SVt_PVCV  Code
  554.          SVt_PVGV  Glob (possible a file handle)
  555.          SVt_PVMG  Blessed or Magical Scalar
  556.  
  557.          See the sv.h header file for more details.
  558.  
  559.  
  560.      BBBBlllleeeesssssssseeeedddd RRRReeeeffffeeeerrrreeeennnncccceeeessss aaaannnndddd CCCCllllaaaassssssss OOOObbbbjjjjeeeeccccttttssss
  561.  
  562.      References are also used to support object-oriented programming.  In the
  563.      OO lexicon, an object is simply a reference that has been blessed into a
  564.      package (or class).  Once blessed, the programmer may now use the
  565.      reference to access the various methods in the class.
  566.  
  567.      A reference can be blessed into a package with the following function:
  568.  
  569.          SV* sv_bless(SV* sv, HV* stash);
  570.  
  571.      The sv argument must be a reference.  The stash argument specifies which
  572.      class the reference will belong to.  See the section on _S_t_a_s_h_e_s _a_n_d _G_l_o_b_s
  573.      for information on converting class names into stashes.
  574.  
  575.      /* Still under construction */
  576.  
  577.      Upgrades rv to reference if not already one.  Creates new SV for rv to
  578.      point to.  If classname is non-null, the SV is blessed into the specified
  579.      class.  SV is returned.
  580.  
  581.              SV* newSVrv(SV* rv, char* classname);
  582.  
  583.      Copies integer or double into an SV whose reference is rv.  SV is blessed
  584.      if classname is non-null.
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.                                                                         PPPPaaaaggggeeee 9999
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  599.  
  600.  
  601.  
  602.              SV* sv_setref_iv(SV* rv, char* classname, IV iv);
  603.              SV* sv_setref_nv(SV* rv, char* classname, NV iv);
  604.  
  605.      Copies the pointer value (_t_h_e _a_d_d_r_e_s_s, _n_o_t _t_h_e _s_t_r_i_n_g!) into an SV whose
  606.      reference is rv.  SV is blessed if classname is non-null.
  607.  
  608.              SV* sv_setref_pv(SV* rv, char* classname, PV iv);
  609.  
  610.      Copies string into an SV whose reference is rv.  Set length to 0 to let
  611.      Perl calculate the string length.  SV is blessed if classname is non-
  612.      null.
  613.  
  614.              SV* sv_setref_pvn(SV* rv, char* classname, PV iv, int length);
  615.  
  616.              int sv_isa(SV* sv, char* name);
  617.              int sv_isobject(SV* sv);
  618.  
  619.  
  620.      CCCCrrrreeeeaaaattttiiiinnnngggg NNNNeeeewwww VVVVaaaarrrriiiiaaaabbbblllleeeessss
  621.  
  622.      To create a new Perl variable with an undef value which can be accessed
  623.      from your Perl script, use the following routines, depending on the
  624.      variable type.
  625.  
  626.          SV*  perl_get_sv("package::varname", TRUE);
  627.          AV*  perl_get_av("package::varname", TRUE);
  628.          HV*  perl_get_hv("package::varname", TRUE);
  629.  
  630.      Notice the use of TRUE as the second parameter.  The new variable can now
  631.      be set, using the routines appropriate to the data type.
  632.  
  633.      There are additional macros whose values may be bitwise OR'ed with the
  634.      TRUE argument to enable certain extra features.  Those bits are:
  635.  
  636.          GV_ADDMULTI Marks the variable as multiply defined, thus preventing the
  637.                      "Name <varname> used only once: possible typo" warning.
  638.          GV_ADDWARN  Issues the warning "Had to create <varname> unexpectedly" if
  639.                      the variable did not exist before the function was called.
  640.  
  641.      If you do not specify a package name, the variable is created in the
  642.      current package.
  643.  
  644.      RRRReeeeffffeeeerrrreeeennnncccceeee CCCCoooouuuunnnnttttssss aaaannnndddd MMMMoooorrrrttttaaaalllliiiittttyyyy
  645.  
  646.      Perl uses an reference count-driven garbage collection mechanism. SVs,
  647.      AVs, or HVs (xV for short in the following) start their life with a
  648.      reference count of 1.  If the reference count of an xV ever drops to 0,
  649.      then it will be destroyed and its memory made available for reuse.
  650.  
  651.      This normally doesn't happen at the Perl level unless a variable is
  652.      undef'ed or the last variable holding a reference to it is changed or
  653.      overwritten.  At the internal level, however, reference counts can be
  654.  
  655.  
  656.  
  657.                                                                        PPPPaaaaggggeeee 11110000
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  665.  
  666.  
  667.  
  668.      manipulated with the following macros:
  669.  
  670.          int SvREFCNT(SV* sv);
  671.          SV* SvREFCNT_inc(SV* sv);
  672.          void SvREFCNT_dec(SV* sv);
  673.  
  674.      However, there is one other function which manipulates the reference
  675.      count of its argument.  The newRV_inc function, you will recall, creates
  676.      a reference to the specified argument.  As a side effect, it increments
  677.      the argument's reference count.  If this is not what you want, use
  678.      newRV_noinc instead.
  679.  
  680.      For example, imagine you want to return a reference from an XSUB
  681.      function.  Inside the XSUB routine, you create an SV which initially has
  682.      a reference count of one.  Then you call newRV_inc, passing it the just-
  683.      created SV.  This returns the reference as a new SV, but the reference
  684.      count of the SV you passed to newRV_inc has been incremented to two.  Now
  685.      you return the reference from the XSUB routine and forget about the SV.
  686.      But Perl hasn't!  Whenever the returned reference is destroyed, the
  687.      reference count of the original SV is decreased to one and nothing
  688.      happens.  The SV will hang around without any way to access it until Perl
  689.      itself terminates.  This is a memory leak.
  690.  
  691.      The correct procedure, then, is to use newRV_noinc instead of newRV_inc.
  692.      Then, if and when the last reference is destroyed, the reference count of
  693.      the SV will go to zero and it will be destroyed, stopping any memory
  694.      leak.
  695.  
  696.      There are some convenience functions available that can help with the
  697.      destruction of xVs.  These functions introduce the concept of
  698.      "mortality".  An xV that is mortal has had its reference count marked to
  699.      be decremented, but not actually decremented, until "a short time later".
  700.      Generally the term "short time later" means a single Perl statement, such
  701.      as a call to an XSUB function.  The actual determinant for when mortal
  702.      xVs have their reference count decremented depends on two macros,
  703.      SAVETMPS and FREETMPS.  See the _p_e_r_l_c_a_l_l manpage and the _p_e_r_l_x_s manpage
  704.      for more details on these macros.
  705.  
  706.      "Mortalization" then is at its simplest a deferred SvREFCNT_dec.
  707.      However, if you mortalize a variable twice, the reference count will
  708.      later be decremented twice.
  709.  
  710.      You should be careful about creating mortal variables.  Strange things
  711.      can happen if you make the same value mortal within multiple contexts, or
  712.      if you make a variable mortal multiple times.
  713.  
  714.      To create a mortal variable, use the functions:
  715.  
  716.          SV*  sv_newmortal()
  717.          SV*  sv_2mortal(SV*)
  718.          SV*  sv_mortalcopy(SV*)
  719.  
  720.  
  721.  
  722.  
  723.                                                                        PPPPaaaaggggeeee 11111111
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  731.  
  732.  
  733.  
  734.      The first call creates a mortal SV, the second converts an existing SV to
  735.      a mortal SV (and thus defers a call to SvREFCNT_dec), and the third
  736.      creates a mortal copy of an existing SV.
  737.  
  738.      The mortal routines are not just for SVs -- AVs and HVs can be made
  739.      mortal by passing their address (type-casted to SV*) to the sv_2mortal or
  740.      sv_mortalcopy routines.
  741.  
  742.      SSSSttttaaaasssshhhheeeessss aaaannnndddd GGGGlllloooobbbbssss
  743.  
  744.      A "stash" is a hash that contains all of the different objects that are
  745.      contained within a package.  Each key of the stash is a symbol name
  746.      (shared by all the different types of objects that have the same name),
  747.      and each value in the hash table is a GV (Glob Value).  This GV in turn
  748.      contains references to the various objects of that name, including (but
  749.      not limited to) the following:
  750.  
  751.          Scalar Value
  752.          Array Value
  753.          Hash Value
  754.          File Handle
  755.          Directory Handle
  756.          Format
  757.          Subroutine
  758.  
  759.      There is a single stash called "defstash" that holds the items that exist
  760.      in the "main" package.  To get at the items in other packages, append the
  761.      string "::" to the package name.  The items in the "Foo" package are in
  762.      the stash "Foo::" in defstash.  The items in the "Bar::Baz" package are
  763.      in the stash "Baz::" in "Bar::"'s stash.
  764.  
  765.      To get the stash pointer for a particular package, use the function:
  766.  
  767.          HV*  gv_stashpv(char* name, I32 create)
  768.          HV*  gv_stashsv(SV*, I32 create)
  769.  
  770.      The first function takes a literal string, the second uses the string
  771.      stored in the SV.  Remember that a stash is just a hash table, so you get
  772.      back an HV*.  The create flag will create a new package if it is set.
  773.  
  774.      The name that gv_stash*v wants is the name of the package whose symbol
  775.      table you want.  The default package is called main.  If you have
  776.      multiply nested packages, pass their names to gv_stash*v, separated by ::
  777.      as in the Perl language itself.
  778.  
  779.      Alternately, if you have an SV that is a blessed reference, you can find
  780.      out the stash pointer by using:
  781.  
  782.          HV*  SvSTASH(SvRV(SV*));
  783.  
  784.      then use the following to get the package name itself:
  785.  
  786.  
  787.  
  788.  
  789.                                                                        PPPPaaaaggggeeee 11112222
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  797.  
  798.  
  799.  
  800.          char*  HvNAME(HV* stash);
  801.  
  802.      If you need to bless or re-bless an object you can use the following
  803.      function:
  804.  
  805.          SV*  sv_bless(SV*, HV* stash)
  806.  
  807.      where the first argument, an SV*, must be a reference, and the second
  808.      argument is a stash.  The returned SV* can now be used in the same way as
  809.      any other SV.
  810.  
  811.      For more information on references and blessings, consult the _p_e_r_l_r_e_f
  812.      manpage.
  813.  
  814.      DDDDoooouuuubbbblllleeee----TTTTyyyyppppeeeedddd SSSSVVVVssss
  815.  
  816.      Scalar variables normally contain only one type of value, an integer,
  817.      double, pointer, or reference.  Perl will automatically convert the
  818.      actual scalar data from the stored type into the requested type.
  819.  
  820.      Some scalar variables contain more than one type of scalar data.  For
  821.      example, the variable $! contains either the numeric value of errno or
  822.      its string equivalent from either strerror or sys_errlist[].
  823.  
  824.      To force multiple data values into an SV, you must do two things: use the
  825.      sv_set*v routines to add the additional scalar type, then set a flag so
  826.      that Perl will believe it contains more than one type of data.  The four
  827.      macros to set the flags are:
  828.  
  829.              SvIOK_on
  830.              SvNOK_on
  831.              SvPOK_on
  832.              SvROK_on
  833.  
  834.      The particular macro you must use depends on which sv_set*v routine you
  835.      called first.  This is because every sv_set*v routine turns on only the
  836.      bit for the particular type of data being set, and turns off all the
  837.      rest.
  838.  
  839.      For example, to create a new Perl variable called "dberror" that contains
  840.      both the numeric and descriptive string error values, you could use the
  841.      following code:
  842.  
  843.          extern int  dberror;
  844.          extern char *dberror_list;
  845.  
  846.          SV* sv = perl_get_sv("dberror", TRUE);
  847.          sv_setiv(sv, (IV) dberror);
  848.          sv_setpv(sv, dberror_list[dberror]);
  849.          SvIOK_on(sv);
  850.  
  851.      If the order of sv_setiv and sv_setpv had been reversed, then the macro
  852.  
  853.  
  854.  
  855.                                                                        PPPPaaaaggggeeee 11113333
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  863.  
  864.  
  865.  
  866.      SvPOK_on would need to be called instead of SvIOK_on.
  867.  
  868.      MMMMaaaaggggiiiicccc VVVVaaaarrrriiiiaaaabbbblllleeeessss
  869.  
  870.      [This section still under construction.  Ignore everything here.  Post no
  871.      bills.  Everything not permitted is forbidden.]
  872.  
  873.      Any SV may be magical, that is, it has special features that a normal SV
  874.      does not have.  These features are stored in the SV structure in a linked
  875.      list of struct magic's, typedef'ed to MAGIC.
  876.  
  877.          struct magic {
  878.              MAGIC*      mg_moremagic;
  879.              MGVTBL*     mg_virtual;
  880.              U16         mg_private;
  881.              char        mg_type;
  882.              U8          mg_flags;
  883.              SV*         mg_obj;
  884.              char*       mg_ptr;
  885.              I32         mg_len;
  886.          };
  887.  
  888.      Note this is current as of patchlevel 0, and could change at any time.
  889.  
  890.      AAAAssssssssiiiiggggnnnniiiinnnngggg MMMMaaaaggggiiiicccc
  891.  
  892.      Perl adds magic to an SV using the sv_magic function:
  893.  
  894.          void sv_magic(SV* sv, SV* obj, int how, char* name, I32 namlen);
  895.  
  896.      The sv argument is a pointer to the SV that is to acquire a new magical
  897.      feature.
  898.  
  899.      If sv is not already magical, Perl uses the SvUPGRADE macro to set the
  900.      SVt_PVMG flag for the sv.  Perl then continues by adding it to the
  901.      beginning of the linked list of magical features.  Any prior entry of the
  902.      same type of magic is deleted.  Note that this can be overridden, and
  903.      multiple instances of the same type of magic can be associated with an
  904.      SV.
  905.  
  906.      The name and namlen arguments are used to associate a string with the
  907.      magic, typically the name of a variable. namlen is stored in the mg_len
  908.      field and if name is non-null and namlen >= 0 a malloc'd copy of the name
  909.      is stored in mg_ptr field.
  910.  
  911.      The sv_magic function uses how to determine which, if any, predefined
  912.      "Magic Virtual Table" should be assigned to the mg_virtual field.  See
  913.      the "Magic Virtual Table" section below.  The how argument is also stored
  914.      in the mg_type field.
  915.  
  916.  
  917.  
  918.  
  919.  
  920.  
  921.                                                                        PPPPaaaaggggeeee 11114444
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  929.  
  930.  
  931.  
  932.      The obj argument is stored in the mg_obj field of the MAGIC structure.
  933.      If it is not the same as the sv argument, the reference count of the obj
  934.      object is incremented.  If it is the same, or if the how argument is "#",
  935.      or if it is a NULL pointer, then obj is merely stored, without the
  936.      reference count being incremented.
  937.  
  938.      There is also a function to add magic to an HV:
  939.  
  940.          void hv_magic(HV *hv, GV *gv, int how);
  941.  
  942.      This simply calls sv_magic and coerces the gv argument into an SV.
  943.  
  944.      To remove the magic from an SV, call the function sv_unmagic:
  945.  
  946.          void sv_unmagic(SV *sv, int type);
  947.  
  948.      The type argument should be equal to the how value when the SV was
  949.      initially made magical.
  950.  
  951.      MMMMaaaaggggiiiicccc VVVViiiirrrrttttuuuuaaaallll TTTTaaaabbbblllleeeessss
  952.  
  953.      The mg_virtual field in the MAGIC structure is a pointer to a MGVTBL,
  954.      which is a structure of function pointers and stands for "Magic Virtual
  955.      Table" to handle the various operations that might be applied to that
  956.      variable.
  957.  
  958.      The MGVTBL has five pointers to the following routine types:
  959.  
  960.          int  (*svt_get)(SV* sv, MAGIC* mg);
  961.          int  (*svt_set)(SV* sv, MAGIC* mg);
  962.          U32  (*svt_len)(SV* sv, MAGIC* mg);
  963.          int  (*svt_clear)(SV* sv, MAGIC* mg);
  964.          int  (*svt_free)(SV* sv, MAGIC* mg);
  965.  
  966.      This MGVTBL structure is set at compile-time in perl.h and there are
  967.      currently 19 types (or 21 with overloading turned on).  These different
  968.      structures contain pointers to various routines that perform additional
  969.      actions depending on which function is being called.
  970.  
  971.          Function pointer    Action taken
  972.          ----------------    ------------
  973.          svt_get             Do something after the value of the SV is retrieved.
  974.          svt_set             Do something after the SV is assigned a value.
  975.          svt_len             Report on the SV's length.
  976.          svt_clear           Clear something the SV represents.
  977.          svt_free            Free any extra storage associated with the SV.
  978.  
  979.      For instance, the MGVTBL structure called vtbl_sv (which corresponds to
  980.      an mg_type of '\0') contains:
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.                                                                        PPPPaaaaggggeeee 11115555
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  995.  
  996.  
  997.  
  998.          { magic_get, magic_set, magic_len, 0, 0 }
  999.  
  1000.      Thus, when an SV is determined to be magical and of type '\0', if a get
  1001.      operation is being performed, the routine magic_get is called.  All the
  1002.      various routines for the various magical types begin with magic_.
  1003.  
  1004.      The current kinds of Magic Virtual Tables are:
  1005.  
  1006.          mg_type  MGVTBL              Type of magic
  1007.          -------  ------              ----------------------------
  1008.          \0       vtbl_sv             Special scalar variable
  1009.          A        vtbl_amagic         %OVERLOAD hash
  1010.          a        vtbl_amagicelem     %OVERLOAD hash element
  1011.          c        (none)              Holds overload table (AMT) on stash
  1012.          B        vtbl_bm             Boyer-Moore (fast string search)
  1013.          E        vtbl_env            %ENV hash
  1014.          e        vtbl_envelem        %ENV hash element
  1015.          f        vtbl_fm             Formline ('compiled' format)
  1016.          g        vtbl_mglob          m//g target / study()ed string
  1017.          I        vtbl_isa            @ISA array
  1018.          i        vtbl_isaelem        @ISA array element
  1019.          k        vtbl_nkeys          scalar(keys()) lvalue
  1020.          L        (none)              Debugger %_<filename
  1021.          l        vtbl_dbline         Debugger %_<filename element
  1022.          o        vtbl_collxfrm       Locale transformation
  1023.          P        vtbl_pack           Tied array or hash
  1024.          p        vtbl_packelem       Tied array or hash element
  1025.          q        vtbl_packelem       Tied scalar or handle
  1026.          S        vtbl_sig            %SIG hash
  1027.          s        vtbl_sigelem        %SIG hash element
  1028.          t        vtbl_taint          Taintedness
  1029.          U        vtbl_uvar           Available for use by extensions
  1030.          v        vtbl_vec            vec() lvalue
  1031.          x        vtbl_substr         substr() lvalue
  1032.          y        vtbl_defelem        Shadow "foreach" iterator variable /
  1033.                                        smart parameter vivification
  1034.          *        vtbl_glob           GV (typeglob)
  1035.          #        vtbl_arylen         Array length ($#ary)
  1036.          .        vtbl_pos            pos() lvalue
  1037.          ~        (none)              Available for use by extensions
  1038.  
  1039.      When an uppercase and lowercase letter both exist in the table, then the
  1040.      uppercase letter is used to represent some kind of composite type (a list
  1041.      or a hash), and the lowercase letter is used to represent an element of
  1042.      that composite type.
  1043.  
  1044.      The '~' and 'U' magic types are defined specifically for use by
  1045.      extensions and will not be used by perl itself.  Extensions can use '~'
  1046.      magic to 'attach' private information to variables (typically objects).
  1047.      This is especially useful because there is no way for normal perl code to
  1048.      corrupt this private information (unlike using extra elements of a hash
  1049.      object).
  1050.  
  1051.  
  1052.  
  1053.                                                                        PPPPaaaaggggeeee 11116666
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  1061.  
  1062.  
  1063.  
  1064.      Similarly, 'U' magic can be used much like _t_i_e() to call a C function any
  1065.      time a scalar's value is used or changed.  The MAGIC's mg_ptr field
  1066.      points to a ufuncs structure:
  1067.  
  1068.          struct ufuncs {
  1069.              I32 (*uf_val)(IV, SV*);
  1070.              I32 (*uf_set)(IV, SV*);
  1071.              IV uf_index;
  1072.          };
  1073.  
  1074.      When the SV is read from or written to, the uf_val or uf_set function
  1075.      will be called with uf_index as the first arg and a pointer to the SV as
  1076.      the second.
  1077.  
  1078.      Note that because multiple extensions may be using '~' or 'U' magic, it
  1079.      is important for extensions to take extra care to avoid conflict.
  1080.      Typically only using the magic on objects blessed into the same class as
  1081.      the extension is sufficient.  For '~' magic, it may also be appropriate
  1082.      to add an I32 'signature' at the top of the private data area and check
  1083.      that.
  1084.  
  1085.      FFFFiiiinnnnddddiiiinnnngggg MMMMaaaaggggiiiicccc
  1086.  
  1087.          MAGIC* mg_find(SV*, int type); /* Finds the magic pointer of that type */
  1088.  
  1089.      This routine returns a pointer to the MAGIC structure stored in the SV.
  1090.      If the SV does not have that magical feature, NULL is returned.  Also, if
  1091.      the SV is not of type SVt_PVMG, Perl may core dump.
  1092.  
  1093.          int mg_copy(SV* sv, SV* nsv, char* key, STRLEN klen);
  1094.  
  1095.      This routine checks to see what types of magic sv has.  If the mg_type
  1096.      field is an uppercase letter, then the mg_obj is copied to nsv, but the
  1097.      mg_type field is changed to be the lowercase letter.
  1098.  
  1099.      UUUUnnnnddddeeeerrrrssssttttaaaannnnddddiiiinnnngggg tttthhhheeee MMMMaaaaggggiiiicccc ooooffff TTTTiiiieeeedddd HHHHaaaasssshhhheeeessss aaaannnndddd AAAArrrrrrrraaaayyyyssss
  1100.  
  1101.      Tied hashes and arrays are magical beasts of the 'P' magic type.
  1102.  
  1103.      WARNING: As of the 5.004 release, proper usage of the array and hash
  1104.      access functions requires understanding a few caveats.  Some of these
  1105.      caveats are actually considered bugs in the API, to be fixed in later
  1106.      releases, and are bracketed with [MAYCHANGE] below. If you find yourself
  1107.      actually applying such information in this section, be aware that the
  1108.      behavior may change in the future, umm, without warning.
  1109.  
  1110.      The av_store function, when given a tied array argument, merely copies
  1111.      the magic of the array onto the value to be "stored", using mg_copy.  It
  1112.      may also return NULL, indicating that the value did not actually need to
  1113.      be stored in the array.  [MAYCHANGE] After a call to av_store on a tied
  1114.      array, the caller will usually need to call mg_set(val) to actually
  1115.      invoke the perl level "STORE" method on the TIEARRAY object.  If av_store
  1116.  
  1117.  
  1118.  
  1119.                                                                        PPPPaaaaggggeeee 11117777
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  1127.  
  1128.  
  1129.  
  1130.      did return NULL, a call to SvREFCNT_dec(val) will also be usually
  1131.      necessary to avoid a memory leak. [/MAYCHANGE]
  1132.  
  1133.      The previous paragraph is applicable verbatim to tied hash access using
  1134.      the hv_store and hv_store_ent functions as well.
  1135.  
  1136.      av_fetch and the corresponding hash functions hv_fetch and hv_fetch_ent
  1137.      actually return an undefined mortal value whose magic has been
  1138.      initialized using mg_copy.  Note the value so returned does not need to
  1139.      be deallocated, as it is already mortal.  [MAYCHANGE] But you will need
  1140.      to call mg_get() on the returned value in order to actually invoke the
  1141.      perl level "FETCH" method on the underlying TIE object.  Similarly, you
  1142.      may also call mg_set() on the return value after possibly assigning a
  1143.      suitable value to it using sv_setsv,  which will invoke the "STORE"
  1144.      method on the TIE object. [/MAYCHANGE]
  1145.  
  1146.      [MAYCHANGE] In other words, the array or hash fetch/store functions don't
  1147.      really fetch and store actual values in the case of tied arrays and
  1148.      hashes.  They merely call mg_copy to attach magic to the values that were
  1149.      meant to be "stored" or "fetched".  Later calls to mg_get and mg_set
  1150.      actually do the job of invoking the TIE methods on the underlying
  1151.      objects.  Thus the magic mechanism currently implements a kind of lazy
  1152.      access to arrays and hashes.
  1153.  
  1154.      Currently (as of perl version 5.004), use of the hash and array access
  1155.      functions requires the user to be aware of whether they are operating on
  1156.      "normal" hashes and arrays, or on their tied variants.  The API may be
  1157.      changed to provide more transparent access to both tied and normal data
  1158.      types in future versions.  [/MAYCHANGE]
  1159.  
  1160.      You would do well to understand that the TIEARRAY and TIEHASH interfaces
  1161.      are mere sugar to invoke some perl method calls while using the uniform
  1162.      hash and array syntax.  The use of this sugar imposes some overhead
  1163.      (typically about two to four extra opcodes per FETCH/STORE operation, in
  1164.      addition to the creation of all the mortal variables required to invoke
  1165.      the methods).  This overhead will be comparatively small if the TIE
  1166.      methods are themselves substantial, but if they are only a few statements
  1167.      long, the overhead will not be insignificant.
  1168.  
  1169.      LLLLooooccccaaaalllliiiizzzziiiinnnngggg cccchhhhaaaannnnggggeeeessss
  1170.  
  1171.      Perl has a very handy construction
  1172.  
  1173.        {
  1174.          local $var = 2;
  1175.          ...
  1176.        }
  1177.  
  1178.      This construction is _a_p_p_r_o_x_i_m_a_t_e_l_y equivalent to
  1179.  
  1180.  
  1181.  
  1182.  
  1183.  
  1184.  
  1185.                                                                        PPPPaaaaggggeeee 11118888
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  1193.  
  1194.  
  1195.  
  1196.        {
  1197.          my $oldvar = $var;
  1198.          $var = 2;
  1199.          ...
  1200.          $var = $oldvar;
  1201.        }
  1202.  
  1203.      The biggest difference is that the first construction would reinstate the
  1204.      initial value of $var, irrespective of how control exits the block: goto,
  1205.      return, die/eval etc. It is a little bit more efficient as well.
  1206.  
  1207.      There is a way to achieve a similar task from C via Perl API: create a
  1208.      _p_s_e_u_d_o-_b_l_o_c_k, and arrange for some changes to be automatically undone at
  1209.      the end of it, either explicit, or via a non-local exit (via _d_i_e()). A
  1210.      _b_l_o_c_k-like construct is created by a pair of ENTER/LEAVE macros (see the
  1211.      section on _E_X_A_M_P_L_E/"_R_e_t_u_r_n_i_n_g _a _S_c_a_l_a_r in the _p_e_r_l_c_a_l_l manpage).  Such a
  1212.      construct may be created specially for some important localized task, or
  1213.      an existing one (like boundaries of enclosing Perl subroutine/block, or
  1214.      an existing pair for freeing TMPs) may be used. (In the second case the
  1215.      overhead of additional localization must be almost negligible.) Note that
  1216.      any XSUB is automatically enclosed in an ENTER/LEAVE pair.
  1217.  
  1218.      Inside such a _p_s_e_u_d_o-_b_l_o_c_k the following service is available:
  1219.  
  1220.      SAVEINT(int i)
  1221.  
  1222.      SAVEIV(IV i)
  1223.  
  1224.      SAVEI32(I32 i)
  1225.  
  1226.      SAVELONG(long i)
  1227.           These macros arrange things to restore the value of integer variable
  1228.           i at the end of enclosing _p_s_e_u_d_o-_b_l_o_c_k.
  1229.  
  1230.      SAVESPTR(s)
  1231.  
  1232.      SAVEPPTR(p)
  1233.           These macros arrange things to restore the value of pointers s and
  1234.           p. s must be a pointer of a type which survives conversion to SV*
  1235.           and back, p should be able to survive conversion to char* and back.
  1236.  
  1237.      SAVEFREESV(SV *sv)
  1238.           The refcount of sv would be decremented at the end of _p_s_e_u_d_o-_b_l_o_c_k.
  1239.           This is similar to sv_2mortal, which should (?) be used instead.
  1240.  
  1241.      SAVEFREEOP(OP *op)
  1242.           The OP * is _o_p__f_r_e_e()ed at the end of _p_s_e_u_d_o-_b_l_o_c_k.
  1243.  
  1244.      SAVEFREEPV(p)
  1245.           The chunk of memory which is pointed to by p is _S_a_f_e_f_r_e_e()ed at the
  1246.           end of _p_s_e_u_d_o-_b_l_o_c_k.
  1247.  
  1248.  
  1249.  
  1250.  
  1251.                                                                        PPPPaaaaggggeeee 11119999
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  1259.  
  1260.  
  1261.  
  1262.      SAVECLEARSV(SV *sv)
  1263.           Clears a slot in the current scratchpad which corresponds to sv at
  1264.           the end of _p_s_e_u_d_o-_b_l_o_c_k.
  1265.  
  1266.      SAVEDELETE(HV *hv, char *key, I32 length)
  1267.           The key key of hv is deleted at the end of _p_s_e_u_d_o-_b_l_o_c_k. The string
  1268.           pointed to by key is _S_a_f_e_f_r_e_e()ed.  If one has a _k_e_y in short-lived
  1269.           storage, the corresponding string may be reallocated like this:
  1270.  
  1271.             SAVEDELETE(defstash, savepv(tmpbuf), strlen(tmpbuf));
  1272.  
  1273.  
  1274.      SAVEDESTRUCTOR(f,p)
  1275.           At the end of _p_s_e_u_d_o-_b_l_o_c_k the function f is called with the only
  1276.           argument (of type void*) p.
  1277.  
  1278.      SAVESTACK_POS()
  1279.           The current offset on the Perl internal stack (cf. SP) is restored
  1280.           at the end of _p_s_e_u_d_o-_b_l_o_c_k.
  1281.  
  1282.      The following API list contains functions, thus one needs to provide
  1283.      pointers to the modifiable data explicitly (either C pointers, or Perlish
  1284.      GV *s).  Where the above macros take int, a similar function takes int *.
  1285.  
  1286.      SV* save_scalar(GV *gv)
  1287.           Equivalent to Perl code local $gv.
  1288.  
  1289.      AV* save_ary(GV *gv)
  1290.  
  1291.      HV* save_hash(GV *gv)
  1292.           Similar to save_scalar, but localize @gv and %gv.
  1293.  
  1294.      void save_item(SV *item)
  1295.           Duplicates the current value of SV, on the exit from the current
  1296.           ENTER/LEAVE _p_s_e_u_d_o-_b_l_o_c_k will restore the value of SV using the
  1297.           stored value.
  1298.  
  1299.      void save_list(SV **sarg, I32 maxsarg)
  1300.           A variant of save_item which takes multiple arguments via an array
  1301.           sarg of SV* of length maxsarg.
  1302.  
  1303.      SV* save_svref(SV **sptr)
  1304.           Similar to save_scalar, but will reinstate a SV *.
  1305.  
  1306.      void save_aptr(AV **aptr)
  1307.  
  1308.      void save_hptr(HV **hptr)
  1309.           Similar to save_svref, but localize AV * and HV *.
  1310.  
  1311.      The Alias module implements localization of the basic types within the
  1312.      _c_a_l_l_e_r'_s _s_c_o_p_e.  People who are interested in how to localize things in
  1313.      the containing scope should take a look there too.
  1314.  
  1315.  
  1316.  
  1317.                                                                        PPPPaaaaggggeeee 22220000
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  1325.  
  1326.  
  1327.  
  1328. SSSSuuuubbbbrrrroooouuuuttttiiiinnnneeeessss
  1329.      XXXXSSSSUUUUBBBBssss aaaannnndddd tttthhhheeee AAAArrrrgggguuuummmmeeeennnntttt SSSSttttaaaacccckkkk
  1330.  
  1331.      The XSUB mechanism is a simple way for Perl programs to access C
  1332.      subroutines.  An XSUB routine will have a stack that contains the
  1333.      arguments from the Perl program, and a way to map from the Perl data
  1334.      structures to a C equivalent.
  1335.  
  1336.      The stack arguments are accessible through the ST(n) macro, which returns
  1337.      the n'th stack argument.  Argument 0 is the first argument passed in the
  1338.      Perl subroutine call.  These arguments are SV*, and can be used anywhere
  1339.      an SV* is used.
  1340.  
  1341.      Most of the time, output from the C routine can be handled through use of
  1342.      the RETVAL and OUTPUT directives.  However, there are some cases where
  1343.      the argument stack is not already long enough to handle all the return
  1344.      values.  An example is the POSIX _t_z_n_a_m_e() call, which takes no arguments,
  1345.      but returns two, the local time zone's standard and summer time
  1346.      abbreviations.
  1347.  
  1348.      To handle this situation, the PPCODE directive is used and the stack is
  1349.      extended using the macro:
  1350.  
  1351.          EXTEND(sp, num);
  1352.  
  1353.      where sp is the stack pointer, and num is the number of elements the
  1354.      stack should be extended by.
  1355.  
  1356.      Now that there is room on the stack, values can be pushed on it using the
  1357.      macros to push IVs, doubles, strings, and SV pointers respectively:
  1358.  
  1359.          PUSHi(IV)
  1360.          PUSHn(double)
  1361.          PUSHp(char*, I32)
  1362.          PUSHs(SV*)
  1363.  
  1364.      And now the Perl program calling tzname, the two values will be assigned
  1365.      as in:
  1366.  
  1367.          ($standard_abbrev, $summer_abbrev) = POSIX::tzname;
  1368.  
  1369.      An alternate (and possibly simpler) method to pushing values on the stack
  1370.      is to use the macros:
  1371.  
  1372.          XPUSHi(IV)
  1373.          XPUSHn(double)
  1374.          XPUSHp(char*, I32)
  1375.          XPUSHs(SV*)
  1376.  
  1377.      These macros automatically adjust the stack for you, if needed.  Thus,
  1378.      you do not need to call EXTEND to extend the stack.
  1379.  
  1380.  
  1381.  
  1382.  
  1383.                                                                        PPPPaaaaggggeeee 22221111
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  1391.  
  1392.  
  1393.  
  1394.      For more information, consult the _p_e_r_l_x_s manpage and the _p_e_r_l_x_s_t_u_t
  1395.      manpage.
  1396.  
  1397.      CCCCaaaalllllllliiiinnnngggg PPPPeeeerrrrllll RRRRoooouuuuttttiiiinnnneeeessss ffffrrrroooommmm wwwwiiiitttthhhhiiiinnnn CCCC PPPPrrrrooooggggrrrraaaammmmssss
  1398.  
  1399.      There are four routines that can be used to call a Perl subroutine from
  1400.      within a C program.  These four are:
  1401.  
  1402.          I32  perl_call_sv(SV*, I32);
  1403.          I32  perl_call_pv(char*, I32);
  1404.          I32  perl_call_method(char*, I32);
  1405.          I32  perl_call_argv(char*, I32, register char**);
  1406.  
  1407.      The routine most often used is perl_call_sv.  The SV* argument contains
  1408.      either the name of the Perl subroutine to be called, or a reference to
  1409.      the subroutine.  The second argument consists of flags that control the
  1410.      context in which the subroutine is called, whether or not the subroutine
  1411.      is being passed arguments, how errors should be trapped, and how to treat
  1412.      return values.
  1413.  
  1414.      All four routines return the number of arguments that the subroutine
  1415.      returned on the Perl stack.
  1416.  
  1417.      When using any of these routines (except perl_call_argv), the programmer
  1418.      must manipulate the Perl stack.  These include the following macros and
  1419.      functions:
  1420.  
  1421.          dSP
  1422.          PUSHMARK()
  1423.          PUTBACK
  1424.          SPAGAIN
  1425.          ENTER
  1426.          SAVETMPS
  1427.          FREETMPS
  1428.          LEAVE
  1429.          XPUSH*()
  1430.          POP*()
  1431.  
  1432.      For a detailed description of calling conventions from C to Perl, consult
  1433.      the _p_e_r_l_c_a_l_l manpage.
  1434.  
  1435.      MMMMeeeemmmmoooorrrryyyy AAAAllllllllooooccccaaaattttiiiioooonnnn
  1436.  
  1437.      It is suggested that you use the version of malloc that is distributed
  1438.      with Perl.  It keeps pools of various sizes of unallocated memory in
  1439.      order to satisfy allocation requests more quickly.  However, on some
  1440.      platforms, it may cause spurious malloc or free errors.
  1441.  
  1442.          New(x, pointer, number, type);
  1443.          Newc(x, pointer, number, type, cast);
  1444.          Newz(x, pointer, number, type);
  1445.  
  1446.  
  1447.  
  1448.  
  1449.                                                                        PPPPaaaaggggeeee 22222222
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  1457.  
  1458.  
  1459.  
  1460.      These three macros are used to initially allocate memory.
  1461.  
  1462.      The first argument x was a "magic cookie" that was used to keep track of
  1463.      who called the macro, to help when debugging memory problems.  However,
  1464.      the current code makes no use of this feature (most Perl developers now
  1465.      use run-time memory checkers), so this argument can be any number.
  1466.  
  1467.      The second argument pointer should be the name of a variable that will
  1468.      point to the newly allocated memory.
  1469.  
  1470.      The third and fourth arguments number and type specify how many of the
  1471.      specified type of data structure should be allocated.  The argument type
  1472.      is passed to sizeof.  The final argument to Newc, cast, should be used if
  1473.      the pointer argument is different from the type argument.
  1474.  
  1475.      Unlike the New and Newc macros, the Newz macro calls memzero to zero out
  1476.      all the newly allocated memory.
  1477.  
  1478.          Renew(pointer, number, type);
  1479.          Renewc(pointer, number, type, cast);
  1480.          Safefree(pointer)
  1481.  
  1482.      These three macros are used to change a memory buffer size or to free a
  1483.      piece of memory no longer needed.  The arguments to Renew and Renewc
  1484.      match those of New and Newc with the exception of not needing the "magic
  1485.      cookie" argument.
  1486.  
  1487.          Move(source, dest, number, type);
  1488.          Copy(source, dest, number, type);
  1489.          Zero(dest, number, type);
  1490.  
  1491.      These three macros are used to move, copy, or zero out previously
  1492.      allocated memory.  The source and dest arguments point to the source and
  1493.      destination starting points.  Perl will move, copy, or zero out number
  1494.      instances of the size of the type data structure (using the sizeof
  1495.      function).
  1496.  
  1497.      PPPPeeeerrrrllllIIIIOOOO
  1498.  
  1499.      The most recent development releases of Perl has been experimenting with
  1500.      removing Perl's dependency on the "normal" standard I/O suite and
  1501.      allowing other stdio implementations to be used.  This involves creating
  1502.      a new abstraction layer that then calls whichever implementation of stdio
  1503.      Perl was compiled with.  All XSUBs should now use the functions in the
  1504.      PerlIO abstraction layer and not make any assumptions about what kind of
  1505.      stdio is being used.
  1506.  
  1507.      For a complete description of the PerlIO abstraction, consult the
  1508.      _p_e_r_l_a_p_i_o manpage.
  1509.  
  1510.  
  1511.  
  1512.  
  1513.  
  1514.  
  1515.                                                                        PPPPaaaaggggeeee 22223333
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  1523.  
  1524.  
  1525.  
  1526.      PPPPuuuuttttttttiiiinnnngggg aaaa CCCC vvvvaaaalllluuuueeee oooonnnn PPPPeeeerrrrllll ssssttttaaaacccckkkk
  1527.  
  1528.      A lot of opcodes (this is an elementary operation in the internal perl
  1529.      stack machine) put an SV* on the stack. However, as an optimization the
  1530.      corresponding SV is (usually) not recreated each time. The opcodes reuse
  1531.      specially assigned SVs (_t_a_r_g_e_ts) which are (as a corollary) not
  1532.      constantly freed/created.
  1533.  
  1534.      Each of the targets is created only once (but see the section on
  1535.      _S_c_r_a_t_c_h_p_a_d_s _a_n_d _r_e_c_u_r_s_i_o_n below), and when an opcode needs to put an
  1536.      integer, a double, or a string on stack, it just sets the corresponding
  1537.      parts of its _t_a_r_g_e_t and puts the _t_a_r_g_e_t on stack.
  1538.  
  1539.      The macro to put this target on stack is PUSHTARG, and it is directly
  1540.      used in some opcodes, as well as indirectly in zillions of others, which
  1541.      use it via (X)PUSH[pni].
  1542.  
  1543.      SSSSccccrrrraaaattttcccchhhhppppaaaaddddssss
  1544.  
  1545.      The question remains on when the SVs which are _t_a_r_g_e_ts for opcodes are
  1546.      created. The answer is that they are created when the current unit -- a
  1547.      subroutine or a file (for opcodes for statements outside of subroutines)
  1548.      -- is compiled. During this time a special anonymous Perl array is
  1549.      created, which is called a scratchpad for the current unit.
  1550.  
  1551.      A scratchpad keeps SVs which are lexicals for the current unit and are
  1552.      targets for opcodes. One can deduce that an SV lives on a scratchpad by
  1553.      looking on its flags: lexicals have SVs_PADMY set, and _t_a_r_g_e_ts have
  1554.      SVs_PADTMP set.
  1555.  
  1556.      The correspondence between OPs and _t_a_r_g_e_ts is not 1-to-1. Different OPs
  1557.      in the compile tree of the unit can use the same target, if this would
  1558.      not conflict with the expected life of the temporary.
  1559.  
  1560.      SSSSccccrrrraaaattttcccchhhhppppaaaaddddssss aaaannnndddd rrrreeeeccccuuuurrrrssssiiiioooonnnn
  1561.  
  1562.      In fact it is not 100% true that a compiled unit contains a pointer to
  1563.      the scratchpad AV. In fact it contains a pointer to an AV of (initially)
  1564.      one element, and this element is the scratchpad AV. Why do we need an
  1565.      extra level of indirection?
  1566.  
  1567.      The answer is rrrreeeeccccuuuurrrrssssiiiioooonnnn, and maybe (sometime soon) tttthhhhrrrreeeeaaaaddddssss. Both these
  1568.      can create several execution pointers going into the same subroutine. For
  1569.      the subroutine-child not write over the temporaries for the subroutine-
  1570.      parent (lifespan of which covers the call to the child), the parent and
  1571.      the child should have different scratchpads. (_A_n_d the lexicals should be
  1572.      separate anyway!)
  1573.  
  1574.      So each subroutine is born with an array of scratchpads (of length 1).
  1575.      On each entry to the subroutine it is checked that the current depth of
  1576.      the recursion is not more than the length of this array, and if it is,
  1577.      new scratchpad is created and pushed into the array.
  1578.  
  1579.  
  1580.  
  1581.                                                                        PPPPaaaaggggeeee 22224444
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  1589.  
  1590.  
  1591.  
  1592.      The _t_a_r_g_e_ts on this scratchpad are undefs, but they are already marked
  1593.      with correct flags.
  1594.  
  1595. CCCCoooommmmppppiiiilllleeeedddd ccccooooddddeeee
  1596.      CCCCooooddddeeee ttttrrrreeeeeeee
  1597.  
  1598.      Here we describe the internal form your code is converted to by Perl.
  1599.      Start with a simple example:
  1600.  
  1601.        $a = $b + $c;
  1602.  
  1603.      This is converted to a tree similar to this one:
  1604.  
  1605.                   assign-to
  1606.                 /           \
  1607.                +             $a
  1608.              /   \
  1609.            $b     $c
  1610.  
  1611.      (but slightly more complicated).  This tree reflect the way Perl parsed
  1612.      your code, but has nothing to do with the execution order.  There is an
  1613.      additional "thread" going through the nodes of the tree which shows the
  1614.      order of execution of the nodes.  In our simplified example above it
  1615.      looks like:
  1616.  
  1617.           $b ---> $c ---> + ---> $a ---> assign-to
  1618.  
  1619.      But with the actual compile tree for $a = $b + $c it is different:  some
  1620.      nodes _o_p_t_i_m_i_z_e_d _a_w_a_y.  As a corollary, though the actual tree contains
  1621.      more nodes than our simplified example, the execution order is the same
  1622.      as in our example.
  1623.  
  1624.      EEEExxxxaaaammmmiiiinnnniiiinnnngggg tttthhhheeee ttttrrrreeeeeeee
  1625.  
  1626.      If you have your perl compiled for debugging (usually done with -D
  1627.      optimize=-g on Configure command line), you may examine the compiled tree
  1628.      by specifying -Dx on the Perl command line.  The output takes several
  1629.      lines per node, and for $b+$c it looks like this:
  1630.  
  1631.  
  1632.  
  1633.  
  1634.  
  1635.  
  1636.  
  1637.  
  1638.  
  1639.  
  1640.  
  1641.  
  1642.  
  1643.  
  1644.  
  1645.  
  1646.  
  1647.                                                                        PPPPaaaaggggeeee 22225555
  1648.  
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  1655.  
  1656.  
  1657.  
  1658.          5           TYPE = add  ===> 6
  1659.                      TARG = 1
  1660.                      FLAGS = (SCALAR,KIDS)
  1661.                      {
  1662.                          TYPE = null  ===> (4)
  1663.                            (was rv2sv)
  1664.                          FLAGS = (SCALAR,KIDS)
  1665.                          {
  1666.          3                   TYPE = gvsv  ===> 4
  1667.                              FLAGS = (SCALAR)
  1668.                              GV = main::b
  1669.                          }
  1670.                      }
  1671.                      {
  1672.                          TYPE = null  ===> (5)
  1673.                            (was rv2sv)
  1674.                          FLAGS = (SCALAR,KIDS)
  1675.                          {
  1676.          4                   TYPE = gvsv  ===> 5
  1677.                              FLAGS = (SCALAR)
  1678.                              GV = main::c
  1679.                          }
  1680.                      }
  1681.  
  1682.      This tree has 5 nodes (one per TYPE specifier), only 3 of them are not
  1683.      optimized away (one per number in the left column).  The immediate
  1684.      children of the given node correspond to {} pairs on the same level of
  1685.      indentation, thus this listing corresponds to the tree:
  1686.  
  1687.                         add
  1688.                       /     \
  1689.                     null    null
  1690.                      |       |
  1691.                     gvsv    gvsv
  1692.  
  1693.      The execution order is indicated by ===> marks, thus it is 3 4 5 6 (node
  1694.      6 is not included into above listing), i.e., gvsv gvsv add whatever.
  1695.  
  1696.      CCCCoooommmmppppiiiilllleeee ppppaaaassssssss 1111:::: cccchhhheeeecccckkkk rrrroooouuuuttttiiiinnnneeeessss
  1697.  
  1698.      The tree is created by the _p_s_e_u_d_o-_c_o_m_p_i_l_e_r while yacc code feeds it the
  1699.      constructions it recognizes. Since yacc works bottom-up, so does the
  1700.      first pass of perl compilation.
  1701.  
  1702.      What makes this pass interesting for perl developers is that some
  1703.      optimization may be performed on this pass.  This is optimization by so-
  1704.      called _c_h_e_c_k _r_o_u_t_i_n_e_s.  The correspondence between node names and
  1705.      corresponding check routines is described in _o_p_c_o_d_e._p_l (do not forget to
  1706.      run make regen_headers if you modify this file).
  1707.  
  1708.  
  1709.  
  1710.  
  1711.  
  1712.  
  1713.                                                                        PPPPaaaaggggeeee 22226666
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  1721.  
  1722.  
  1723.  
  1724.      A check routine is called when the node is fully constructed except for
  1725.      the execution-order thread.  Since at this time there is no back-links to
  1726.      the currently constructed node, one can do most any operation to the
  1727.      top-level node, including freeing it and/or creating new nodes
  1728.      above/below it.
  1729.  
  1730.      The check routine returns the node which should be inserted into the tree
  1731.      (if the top-level node was not modified, check routine returns its
  1732.      argument).
  1733.  
  1734.      By convention, check routines have names ck_*. They are usually called
  1735.      from new*OP subroutines (or convert) (which in turn are called from
  1736.      _p_e_r_l_y._y).
  1737.  
  1738.      CCCCoooommmmppppiiiilllleeee ppppaaaassssssss 1111aaaa:::: ccccoooonnnnssssttttaaaannnntttt ffffoooollllddddiiiinnnngggg
  1739.  
  1740.      Immediately after the check routine is called the returned node is
  1741.      checked for being compile-time executable.  If it is (the value is judged
  1742.      to be constant) it is immediately executed, and a _c_o_n_s_t_a_n_t node with the
  1743.      "return value" of the corresponding subtree is substituted instead.  The
  1744.      subtree is deleted.
  1745.  
  1746.      If constant folding was not performed, the execution-order thread is
  1747.      created.
  1748.  
  1749.      CCCCoooommmmppppiiiilllleeee ppppaaaassssssss 2222:::: ccccoooonnnntttteeeexxxxtttt pppprrrrooooppppaaaaggggaaaattttiiiioooonnnn
  1750.  
  1751.      When a context for a part of compile tree is known, it is propagated down
  1752.      through the tree.  Aat this time the context can have 5 values (instead
  1753.      of 2 for runtime context): void, boolean, scalar, list, and lvalue.  In
  1754.      contrast with the pass 1 this pass is processed from top to bottom: a
  1755.      node's context determines the context for its children.
  1756.  
  1757.      Additional context-dependent optimizations are performed at this time.
  1758.      Since at this moment the compile tree contains back-references (via
  1759.      "thread" pointers), nodes cannot be _f_r_e_e()d now.  To allow optimized-away
  1760.      nodes at this stage, such nodes are _n_u_l_l()ified instead of _f_r_e_e()ing
  1761.      (i.e. their type is changed to OP_NULL).
  1762.  
  1763.      CCCCoooommmmppppiiiilllleeee ppppaaaassssssss 3333:::: ppppeeeeeeeepppphhhhoooolllleeee ooooppppttttiiiimmmmiiiizzzzaaaattttiiiioooonnnn
  1764.  
  1765.      After the compile tree for a subroutine (or for an eval or a file) is
  1766.      created, an additional pass over the code is performed. This pass is
  1767.      neither top-down or bottom-up, but in the execution order (with
  1768.      additional compilications for conditionals).  These optimizations are
  1769.      done in the subroutine _p_e_e_p().  Optimizations performed at this stage are
  1770.      subject to the same restrictions as in the pass 2.
  1771.  
  1772. AAAAPPPPIIII LLLLIIIISSSSTTTTIIIINNNNGGGG
  1773.      This is a listing of functions, macros, flags, and variables that may be
  1774.      useful to extension writers or that may be found while reading other
  1775.      extensions.
  1776.  
  1777.  
  1778.  
  1779.                                                                        PPPPaaaaggggeeee 22227777
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  1787.  
  1788.  
  1789.  
  1790.      AvFILL  Same as av_len.
  1791.  
  1792.      av_clear
  1793.              Clears an array, making it empty.  Does not free the memory used
  1794.              by the array itself.
  1795.  
  1796.                      void    av_clear _((AV* ar));
  1797.  
  1798.  
  1799.      av_extend
  1800.              Pre-extend an array.  The key is the index to which the array
  1801.              should be extended.
  1802.  
  1803.                      void    av_extend _((AV* ar, I32 key));
  1804.  
  1805.  
  1806.      av_fetch
  1807.              Returns the SV at the specified index in the array.  The key is
  1808.              the index.  If lval is set then the fetch will be part of a
  1809.              store.  Check that the return value is non-null before
  1810.              dereferencing it to a SV*.
  1811.  
  1812.              See the section on _U_n_d_e_r_s_t_a_n_d_i_n_g _t_h_e _M_a_g_i_c _o_f _T_i_e_d _H_a_s_h_e_s _a_n_d
  1813.              _A_r_r_a_y_s for more information on how to use this function on tied
  1814.              arrays.
  1815.  
  1816.                      SV**    av_fetch _((AV* ar, I32 key, I32 lval));
  1817.  
  1818.  
  1819.      av_len  Returns the highest index in the array.  Returns -1 if the array
  1820.              is empty.
  1821.  
  1822.                      I32     av_len _((AV* ar));
  1823.  
  1824.  
  1825.      av_make Creates a new AV and populates it with a list of SVs.  The SVs
  1826.              are copied into the array, so they may be freed after the call to
  1827.              av_make.  The new AV will have a reference count of 1.
  1828.  
  1829.                      AV*     av_make _((I32 size, SV** svp));
  1830.  
  1831.  
  1832.      av_pop  Pops an SV off the end of the array.  Returns &sv_undef if the
  1833.              array is empty.
  1834.  
  1835.                      SV*     av_pop _((AV* ar));
  1836.  
  1837.  
  1838.      av_push Pushes an SV onto the end of the array.  The array will grow
  1839.              automatically to accommodate the addition.
  1840.  
  1841.                      void    av_push _((AV* ar, SV* val));
  1842.  
  1843.  
  1844.  
  1845.                                                                        PPPPaaaaggggeeee 22228888
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  1853.  
  1854.  
  1855.  
  1856.      av_shift
  1857.              Shifts an SV off the beginning of the array.
  1858.  
  1859.                      SV*     av_shift _((AV* ar));
  1860.  
  1861.  
  1862.      av_store
  1863.              Stores an SV in an array.  The array index is specified as key.
  1864.              The return value will be NULL if the operation failed or if the
  1865.              value did not need to be actually stored within the array (as in
  1866.              the case of tied arrays).  Otherwise it can be dereferenced to
  1867.              get the original SV*.  Note that the caller is responsible for
  1868.              suitably incrementing the reference count of val before the call,
  1869.              and decrementing it if the function returned NULL.
  1870.  
  1871.              See the section on _U_n_d_e_r_s_t_a_n_d_i_n_g _t_h_e _M_a_g_i_c _o_f _T_i_e_d _H_a_s_h_e_s _a_n_d
  1872.              _A_r_r_a_y_s for more information on how to use this function on tied
  1873.              arrays.
  1874.  
  1875.                      SV**    av_store _((AV* ar, I32 key, SV* val));
  1876.  
  1877.  
  1878.      av_undef
  1879.              Undefines the array.  Frees the memory used by the array itself.
  1880.  
  1881.                      void    av_undef _((AV* ar));
  1882.  
  1883.  
  1884.      av_unshift
  1885.              Unshift the given number of undef values onto the beginning of
  1886.              the array.  The array will grow automatically to accommodate the
  1887.              addition.  You must then use av_store to assign values to these
  1888.              new elements.
  1889.  
  1890.                      void    av_unshift _((AV* ar, I32 num));
  1891.  
  1892.  
  1893.      CLASS   Variable which is setup by xsubpp to indicate the class name for
  1894.              a C++ XS constructor.  This is always a char*.  See THIS and the
  1895.              section on _U_s_i_n_g _X_S _W_i_t_h _C++ in the _p_e_r_l_x_s manpage.
  1896.  
  1897.      Copy    The XSUB-writer's interface to the C memcpy function.  The s is
  1898.              the source, d is the destination, n is the number of items, and t
  1899.              is the type.  May fail on overlapping copies.  See also Move.
  1900.  
  1901.                      (void) Copy( s, d, n, t );
  1902.  
  1903.  
  1904.      croak   This is the XSUB-writer's interface to Perl's die function.  Use
  1905.              this function the same way you use the C printf function.  See
  1906.              warn.
  1907.  
  1908.  
  1909.  
  1910.  
  1911.                                                                        PPPPaaaaggggeeee 22229999
  1912.  
  1913.  
  1914.  
  1915.  
  1916.  
  1917.  
  1918. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  1919.  
  1920.  
  1921.  
  1922.      CvSTASH Returns the stash of the CV.
  1923.  
  1924.                      HV * CvSTASH( SV* sv )
  1925.  
  1926.  
  1927.      DBsingle
  1928.              When Perl is run in debugging mode, with the ----dddd switch, this SV
  1929.              is a boolean which indicates whether subs are being single-
  1930.              stepped.  Single-stepping is automatically turned on after every
  1931.              step.  This is the C variable which corresponds to Perl's
  1932.              $DB::single variable.  See DBsub.
  1933.  
  1934.      DBsub   When Perl is run in debugging mode, with the ----dddd switch, this GV
  1935.              contains the SV which holds the name of the sub being debugged.
  1936.              This is the C variable which corresponds to Perl's $DB::sub
  1937.              variable.  See DBsingle.  The sub name can be found by
  1938.  
  1939.                      SvPV( GvSV( DBsub ), na )
  1940.  
  1941.  
  1942.      DBtrace Trace variable used when Perl is run in debugging mode, with the
  1943.              ----dddd switch.  This is the C variable which corresponds to Perl's
  1944.              $DB::trace variable.  See DBsingle.
  1945.  
  1946.      dMARK   Declare a stack marker variable, mark, for the XSUB.  See MARK
  1947.              and dORIGMARK.
  1948.  
  1949.      dORIGMARK
  1950.              Saves the original stack mark for the XSUB.  See ORIGMARK.
  1951.  
  1952.      dowarn  The C variable which corresponds to Perl's $^W warning variable.
  1953.  
  1954.      dSP     Declares a stack pointer variable, sp, for the XSUB.  See SP.
  1955.  
  1956.      dXSARGS Sets up stack and mark pointers for an XSUB, calling dSP and
  1957.              dMARK.  This is usually handled automatically by xsubpp.
  1958.              Declares the items variable to indicate the number of items on
  1959.              the stack.
  1960.  
  1961.      dXSI32  Sets up the ix variable for an XSUB which has aliases.  This is
  1962.              usually handled automatically by xsubpp.
  1963.  
  1964.      ENTER   Opening bracket on a callback.  See LEAVE and the _p_e_r_l_c_a_l_l
  1965.              manpage.
  1966.  
  1967.                      ENTER;
  1968.  
  1969.  
  1970.      EXTEND  Used to extend the argument stack for an XSUB's return values.
  1971.  
  1972.                      EXTEND( sp, int x );
  1973.  
  1974.  
  1975.  
  1976.  
  1977.                                                                        PPPPaaaaggggeeee 33330000
  1978.  
  1979.  
  1980.  
  1981.  
  1982.  
  1983.  
  1984. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  1985.  
  1986.  
  1987.  
  1988.      FREETMPS
  1989.              Closing bracket for temporaries on a callback.  See SAVETMPS and
  1990.              the _p_e_r_l_c_a_l_l manpage.
  1991.  
  1992.                      FREETMPS;
  1993.  
  1994.  
  1995.      G_ARRAY Used to indicate array context.  See GIMME_V, GIMME and the
  1996.              _p_e_r_l_c_a_l_l manpage.
  1997.  
  1998.      G_DISCARD
  1999.              Indicates that arguments returned from a callback should be
  2000.              discarded.  See the _p_e_r_l_c_a_l_l manpage.
  2001.  
  2002.      G_EVAL  Used to force a Perl eval wrapper around a callback.  See the
  2003.              _p_e_r_l_c_a_l_l manpage.
  2004.  
  2005.      GIMME   A backward-compatible version of GIMME_V which can only return
  2006.              G_SCALAR or G_ARRAY; in a void context, it returns G_SCALAR.
  2007.  
  2008.      GIMME_V The XSUB-writer's equivalent to Perl's wantarray.  Returns
  2009.              G_VOID, G_SCALAR or G_ARRAY for void, scalar or array context,
  2010.              respectively.
  2011.  
  2012.      G_NOARGS
  2013.              Indicates that no arguments are being sent to a callback.  See
  2014.              the _p_e_r_l_c_a_l_l manpage.
  2015.  
  2016.      G_SCALAR
  2017.              Used to indicate scalar context.  See GIMME_V, GIMME, and the
  2018.              _p_e_r_l_c_a_l_l manpage.
  2019.  
  2020.      G_VOID  Used to indicate void context.  See GIMME_V and the _p_e_r_l_c_a_l_l
  2021.              manpage.
  2022.  
  2023.      gv_fetchmeth
  2024.              Returns the glob with the given name and a defined subroutine or
  2025.              NULL.  The glob lives in the given stash, or in the stashes
  2026.              accessable via @ISA and @<UNIVERSAL>.
  2027.  
  2028.              The argument level should be either 0 or -1.  If level==0, as a
  2029.              side-effect creates a glob with the given name in the given stash
  2030.              which in the case of success contains an alias for the
  2031.              subroutine, and sets up caching info for this glob.  Similarly
  2032.              for all the searched stashes.
  2033.  
  2034.              This function grants "SUPER" token as a postfix of the stash
  2035.              name.
  2036.  
  2037.              The GV returned from gv_fetchmeth may be a method cache entry,
  2038.              which is not visible to Perl code.  So when calling perl_call_sv,
  2039.              you should not use the GV directly; instead, you should use the
  2040.  
  2041.  
  2042.  
  2043.                                                                        PPPPaaaaggggeeee 33331111
  2044.  
  2045.  
  2046.  
  2047.  
  2048.  
  2049.  
  2050. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  2051.  
  2052.  
  2053.  
  2054.              method's CV, which can be obtained from the GV with the GvCV
  2055.              macro.
  2056.  
  2057.                      GV*     gv_fetchmeth _((HV* stash, char* name, STRLEN len, I32 level));
  2058.  
  2059.  
  2060.      gv_fetchmethod
  2061.  
  2062.      gv_fetchmethod_autoload
  2063.              Returns the glob which contains the subroutine to call to invoke
  2064.              the method on the stash.  In fact in the presense of autoloading
  2065.              this may be the glob for "AUTOLOAD".  In this case the
  2066.              corresponding variable $AUTOLOAD is already setup.
  2067.  
  2068.              The third parameter of gv_fetchmethod_autoload determines whether
  2069.              AUTOLOAD lookup is performed if the given method is not present:
  2070.              non-zero means yes, look for AUTOLOAD; zero means no, don't look
  2071.              for AUTOLOAD.  Calling gv_fetchmethod is equivalent to calling
  2072.              gv_fetchmethod_autoload with a non-zero autoload parameter.
  2073.  
  2074.              These functions grant "SUPER" token as a prefix of the method
  2075.              name.
  2076.  
  2077.              Note that if you want to keep the returned glob for a long time,
  2078.              you need to check for it being "AUTOLOAD", since at the later
  2079.              time the call may load a different subroutine due to $AUTOLOAD
  2080.              changing its value.  Use the glob created via a side effect to do
  2081.              this.
  2082.  
  2083.              These functions have the same side-effects and as gv_fetchmeth
  2084.              with level==0.  name should be writable if contains ':' or '\''.
  2085.              The warning against passing the GV returned by gv_fetchmeth to
  2086.              perl_call_sv apply equally to these functions.
  2087.  
  2088.                      GV*     gv_fetchmethod _((HV* stash, char* name));
  2089.                      GV*     gv_fetchmethod_autoload _((HV* stash, char* name,
  2090.                                                         I32 autoload));
  2091.  
  2092.  
  2093.      gv_stashpv
  2094.              Returns a pointer to the stash for a specified package.  If
  2095.              create is set then the package will be created if it does not
  2096.              already exist.  If create is not set and the package does not
  2097.              exist then NULL is returned.
  2098.  
  2099.                      HV*     gv_stashpv _((char* name, I32 create));
  2100.  
  2101.  
  2102.      gv_stashsv
  2103.              Returns a pointer to the stash for a specified package.  See
  2104.              gv_stashpv.
  2105.  
  2106.  
  2107.  
  2108.  
  2109.                                                                        PPPPaaaaggggeeee 33332222
  2110.  
  2111.  
  2112.  
  2113.  
  2114.  
  2115.  
  2116. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  2117.  
  2118.  
  2119.  
  2120.                      HV*     gv_stashsv _((SV* sv, I32 create));
  2121.  
  2122.  
  2123.      GvSV    Return the SV from the GV.
  2124.  
  2125.      HEf_SVKEY
  2126.              This flag, used in the length slot of hash entries and magic
  2127.              structures, specifies the structure contains a SV* pointer where
  2128.              a char* pointer is to be expected. (For information only--not to
  2129.              be used).
  2130.  
  2131.      HeHASH  Returns the computed hash (type U32) stored in the hash entry.
  2132.  
  2133.                      HeHASH(HE* he)
  2134.  
  2135.  
  2136.      HeKEY   Returns the actual pointer stored in the key slot of the hash
  2137.              entry.  The pointer may be either char* or SV*, depending on the
  2138.              value of HeKLEN().  Can be assigned to.  The HePV() or HeSVKEY()
  2139.              macros are usually preferable for finding the value of a key.
  2140.  
  2141.                      HeKEY(HE* he)
  2142.  
  2143.  
  2144.      HeKLEN  If this is negative, and amounts to HEf_SVKEY, it indicates the
  2145.              entry holds an SV* key.  Otherwise, holds the actual length of
  2146.              the key.  Can be assigned to. The HePV() macro is usually
  2147.              preferable for finding key lengths.
  2148.  
  2149.                      HeKLEN(HE* he)
  2150.  
  2151.  
  2152.      HePV    Returns the key slot of the hash entry as a char* value, doing
  2153.              any necessary dereferencing of possibly SV* keys.  The length of
  2154.              the string is placed in len (this is a macro, so do _n_o_t use
  2155.              &len).  If you do not care about what the length of the key is,
  2156.              you may use the global variable na.  Remember though, that hash
  2157.              keys in perl are free to contain embedded nulls, so using
  2158.              strlen() or similar is not a good way to find the length of hash
  2159.              keys.  This is very similar to the SvPV() macro described
  2160.              elsewhere in this document.
  2161.  
  2162.                      HePV(HE* he, STRLEN len)
  2163.  
  2164.  
  2165.      HeSVKEY Returns the key as an SV*, or Nullsv if the hash entry does not
  2166.              contain an SV* key.
  2167.  
  2168.                      HeSVKEY(HE* he)
  2169.  
  2170.  
  2171.  
  2172.  
  2173.  
  2174.  
  2175.                                                                        PPPPaaaaggggeeee 33333333
  2176.  
  2177.  
  2178.  
  2179.  
  2180.  
  2181.  
  2182. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  2183.  
  2184.  
  2185.  
  2186.      HeSVKEY_force
  2187.              Returns the key as an SV*.  Will create and return a temporary
  2188.              mortal SV* if the hash entry contains only a char* key.
  2189.  
  2190.                      HeSVKEY_force(HE* he)
  2191.  
  2192.  
  2193.      HeSVKEY_set
  2194.              Sets the key to a given SV*, taking care to set the appropriate
  2195.              flags to indicate the presence of an SV* key, and returns the
  2196.              same SV*.
  2197.  
  2198.                      HeSVKEY_set(HE* he, SV* sv)
  2199.  
  2200.  
  2201.      HeVAL   Returns the value slot (type SV*) stored in the hash entry.
  2202.  
  2203.                      HeVAL(HE* he)
  2204.  
  2205.  
  2206.      hv_clear
  2207.              Clears a hash, making it empty.
  2208.  
  2209.                      void    hv_clear _((HV* tb));
  2210.  
  2211.  
  2212.      hv_delayfree_ent
  2213.              Releases a hash entry, such as while iterating though the hash,
  2214.              but delays actual freeing of key and value until the end of the
  2215.              current statement (or thereabouts) with sv_2mortal.  See
  2216.              hv_iternext and hv_free_ent.
  2217.  
  2218.                      void    hv_delayfree_ent _((HV* hv, HE* entry));
  2219.  
  2220.  
  2221.      hv_delete
  2222.              Deletes a key/value pair in the hash.  The value SV is removed
  2223.              from the hash and returned to the caller.  The klen is the length
  2224.              of the key.  The flags value will normally be zero; if set to
  2225.              G_DISCARD then NULL will be returned.
  2226.  
  2227.                      SV*     hv_delete _((HV* tb, char* key, U32 klen, I32 flags));
  2228.  
  2229.  
  2230.      hv_delete_ent
  2231.              Deletes a key/value pair in the hash.  The value SV is removed
  2232.              from the hash and returned to the caller.  The flags value will
  2233.              normally be zero; if set to G_DISCARD then NULL will be returned.
  2234.              hash can be a valid precomputed hash value, or 0 to ask for it to
  2235.              be computed.
  2236.  
  2237.                      SV*     hv_delete_ent _((HV* tb, SV* key, I32 flags, U32 hash));
  2238.  
  2239.  
  2240.  
  2241.                                                                        PPPPaaaaggggeeee 33334444
  2242.  
  2243.  
  2244.  
  2245.  
  2246.  
  2247.  
  2248. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  2249.  
  2250.  
  2251.  
  2252.      hv_exists
  2253.              Returns a boolean indicating whether the specified hash key
  2254.              exists.  The klen is the length of the key.
  2255.  
  2256.                      bool    hv_exists _((HV* tb, char* key, U32 klen));
  2257.  
  2258.  
  2259.      hv_exists_ent
  2260.              Returns a boolean indicating whether the specified hash key
  2261.              exists. hash can be a valid precomputed hash value, or 0 to ask
  2262.              for it to be computed.
  2263.  
  2264.                      bool    hv_exists_ent _((HV* tb, SV* key, U32 hash));
  2265.  
  2266.  
  2267.      hv_fetch
  2268.              Returns the SV which corresponds to the specified key in the
  2269.              hash.  The klen is the length of the key.  If lval is set then
  2270.              the fetch will be part of a store.  Check that the return value
  2271.              is non-null before dereferencing it to a SV*.
  2272.  
  2273.              See the section on _U_n_d_e_r_s_t_a_n_d_i_n_g _t_h_e _M_a_g_i_c _o_f _T_i_e_d _H_a_s_h_e_s _a_n_d
  2274.              _A_r_r_a_y_s for more information on how to use this function on tied
  2275.              hashes.
  2276.  
  2277.                      SV**    hv_fetch _((HV* tb, char* key, U32 klen, I32 lval));
  2278.  
  2279.  
  2280.      hv_fetch_ent
  2281.              Returns the hash entry which corresponds to the specified key in
  2282.              the hash.  hash must be a valid precomputed hash number for the
  2283.              given key, or 0 if you want the function to compute it.  IF lval
  2284.              is set then the fetch will be part of a store.  Make sure the
  2285.              return value is non-null before accessing it.  The return value
  2286.              when tb is a tied hash is a pointer to a static location, so be
  2287.              sure to make a copy of the structure if you need to store it
  2288.              somewhere.
  2289.  
  2290.              See the section on _U_n_d_e_r_s_t_a_n_d_i_n_g _t_h_e _M_a_g_i_c _o_f _T_i_e_d _H_a_s_h_e_s _a_n_d
  2291.              _A_r_r_a_y_s for more information on how to use this function on tied
  2292.              hashes.
  2293.  
  2294.                      HE*     hv_fetch_ent  _((HV* tb, SV* key, I32 lval, U32 hash));
  2295.  
  2296.  
  2297.      hv_free_ent
  2298.              Releases a hash entry, such as while iterating though the hash.
  2299.              See hv_iternext and hv_delayfree_ent.
  2300.  
  2301.                      void    hv_free_ent _((HV* hv, HE* entry));
  2302.  
  2303.  
  2304.  
  2305.  
  2306.  
  2307.                                                                        PPPPaaaaggggeeee 33335555
  2308.  
  2309.  
  2310.  
  2311.  
  2312.  
  2313.  
  2314. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  2315.  
  2316.  
  2317.  
  2318.      hv_iterinit
  2319.              Prepares a starting point to traverse a hash table.
  2320.  
  2321.                      I32     hv_iterinit _((HV* tb));
  2322.  
  2323.              Note that hv_iterinit _c_u_r_r_e_n_t_l_y returns the number of _b_u_c_k_e_t_s in
  2324.              the hash and _n_o_t the number of keys (as indicated in the Advanced
  2325.              Perl Programming book). This may change in future. Use the
  2326.              _H_v_K_E_Y_S(hv) macro to find the number of keys in a hash.
  2327.  
  2328.      hv_iterkey
  2329.              Returns the key from the current position of the hash iterator.
  2330.              See hv_iterinit.
  2331.  
  2332.                      char*   hv_iterkey _((HE* entry, I32* retlen));
  2333.  
  2334.  
  2335.      hv_iterkeysv
  2336.              Returns the key as an SV* from the current position of the hash
  2337.              iterator.  The return value will always be a mortal copy of the
  2338.              key.  Also see hv_iterinit.
  2339.  
  2340.                      SV*     hv_iterkeysv  _((HE* entry));
  2341.  
  2342.  
  2343.      hv_iternext
  2344.              Returns entries from a hash iterator.  See hv_iterinit.
  2345.  
  2346.                      HE*     hv_iternext _((HV* tb));
  2347.  
  2348.  
  2349.      hv_iternextsv
  2350.              Performs an hv_iternext, hv_iterkey, and hv_iterval in one
  2351.              operation.
  2352.  
  2353.                      SV *    hv_iternextsv _((HV* hv, char** key, I32* retlen));
  2354.  
  2355.  
  2356.      hv_iterval
  2357.              Returns the value from the current position of the hash iterator.
  2358.              See hv_iterkey.
  2359.  
  2360.                      SV*     hv_iterval _((HV* tb, HE* entry));
  2361.  
  2362.  
  2363.      hv_magic
  2364.              Adds magic to a hash.  See sv_magic.
  2365.  
  2366.                      void    hv_magic _((HV* hv, GV* gv, int how));
  2367.  
  2368.  
  2369.  
  2370.  
  2371.  
  2372.  
  2373.                                                                        PPPPaaaaggggeeee 33336666
  2374.  
  2375.  
  2376.  
  2377.  
  2378.  
  2379.  
  2380. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  2381.  
  2382.  
  2383.  
  2384.      HvNAME  Returns the package name of a stash.  See SvSTASH, CvSTASH.
  2385.  
  2386.                      char *HvNAME (HV* stash)
  2387.  
  2388.  
  2389.      hv_store
  2390.              Stores an SV in a hash.  The hash key is specified as key and
  2391.              klen is the length of the key.  The hash parameter is the
  2392.              precomputed hash value; if it is zero then Perl will compute it.
  2393.              The return value will be NULL if the operation failed or if the
  2394.              value did not need to be actually stored within the hash (as in
  2395.              the case of tied hashes).  Otherwise it can be dereferenced to
  2396.              get the original SV*.  Note that the caller is responsible for
  2397.              suitably incrementing the reference count of val before the call,
  2398.              and decrementing it if the function returned NULL.
  2399.  
  2400.              See the section on _U_n_d_e_r_s_t_a_n_d_i_n_g _t_h_e _M_a_g_i_c _o_f _T_i_e_d _H_a_s_h_e_s _a_n_d
  2401.              _A_r_r_a_y_s for more information on how to use this function on tied
  2402.              hashes.
  2403.  
  2404.                      SV**    hv_store _((HV* tb, char* key, U32 klen, SV* val, U32 hash));
  2405.  
  2406.  
  2407.      hv_store_ent
  2408.              Stores val in a hash.  The hash key is specified as key.  The
  2409.              hash parameter is the precomputed hash value; if it is zero then
  2410.              Perl will compute it.  The return value is the new hash entry so
  2411.              created.  It will be NULL if the operation failed or if the value
  2412.              did not need to be actually stored within the hash (as in the
  2413.              case of tied hashes).  Otherwise the contents of the return value
  2414.              can be accessed using the He??? macros described here.  Note that
  2415.              the caller is responsible for suitably incrementing the reference
  2416.              count of val before the call, and decrementing it if the function
  2417.              returned NULL.
  2418.  
  2419.              See the section on _U_n_d_e_r_s_t_a_n_d_i_n_g _t_h_e _M_a_g_i_c _o_f _T_i_e_d _H_a_s_h_e_s _a_n_d
  2420.              _A_r_r_a_y_s for more information on how to use this function on tied
  2421.              hashes.
  2422.  
  2423.                      HE*     hv_store_ent  _((HV* tb, SV* key, SV* val, U32 hash));
  2424.  
  2425.  
  2426.      hv_undef
  2427.              Undefines the hash.
  2428.  
  2429.                      void    hv_undef _((HV* tb));
  2430.  
  2431.  
  2432.      isALNUM Returns a boolean indicating whether the C char is an ascii
  2433.              alphanumeric character or digit.
  2434.  
  2435.                      int isALNUM (char c)
  2436.  
  2437.  
  2438.  
  2439.                                                                        PPPPaaaaggggeeee 33337777
  2440.  
  2441.  
  2442.  
  2443.  
  2444.  
  2445.  
  2446. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  2447.  
  2448.  
  2449.  
  2450.      isALPHA Returns a boolean indicating whether the C char is an ascii
  2451.              alphabetic character.
  2452.  
  2453.                      int isALPHA (char c)
  2454.  
  2455.  
  2456.      isDIGIT Returns a boolean indicating whether the C char is an ascii
  2457.              digit.
  2458.  
  2459.                      int isDIGIT (char c)
  2460.  
  2461.  
  2462.      isLOWER Returns a boolean indicating whether the C char is a lowercase
  2463.              character.
  2464.  
  2465.                      int isLOWER (char c)
  2466.  
  2467.  
  2468.      isSPACE Returns a boolean indicating whether the C char is whitespace.
  2469.  
  2470.                      int isSPACE (char c)
  2471.  
  2472.  
  2473.      isUPPER Returns a boolean indicating whether the C char is an uppercase
  2474.              character.
  2475.  
  2476.                      int isUPPER (char c)
  2477.  
  2478.  
  2479.      items   Variable which is setup by xsubpp to indicate the number of items
  2480.              on the stack.  See the section on _V_a_r_i_a_b_l_e-_l_e_n_g_t_h _P_a_r_a_m_e_t_e_r _L_i_s_t_s
  2481.              in the _p_e_r_l_x_s manpage.
  2482.  
  2483.      ix      Variable which is setup by xsubpp to indicate which of an XSUB's
  2484.              aliases was used to invoke it.  See the section on _T_h_e _A_L_I_A_S:
  2485.              _K_e_y_w_o_r_d in the _p_e_r_l_x_s manpage.
  2486.  
  2487.      LEAVE   Closing bracket on a callback.  See ENTER and the _p_e_r_l_c_a_l_l
  2488.              manpage.
  2489.  
  2490.                      LEAVE;
  2491.  
  2492.  
  2493.      MARK    Stack marker variable for the XSUB.  See dMARK.
  2494.  
  2495.      mg_clear
  2496.              Clear something magical that the SV represents.  See sv_magic.
  2497.  
  2498.                      int     mg_clear _((SV* sv));
  2499.  
  2500.  
  2501.  
  2502.  
  2503.  
  2504.  
  2505.                                                                        PPPPaaaaggggeeee 33338888
  2506.  
  2507.  
  2508.  
  2509.  
  2510.  
  2511.  
  2512. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  2513.  
  2514.  
  2515.  
  2516.      mg_copy Copies the magic from one SV to another.  See sv_magic.
  2517.  
  2518.                      int     mg_copy _((SV *, SV *, char *, STRLEN));
  2519.  
  2520.  
  2521.      mg_find Finds the magic pointer for type matching the SV.  See sv_magic.
  2522.  
  2523.                      MAGIC*  mg_find _((SV* sv, int type));
  2524.  
  2525.  
  2526.      mg_free Free any magic storage used by the SV.  See sv_magic.
  2527.  
  2528.                      int     mg_free _((SV* sv));
  2529.  
  2530.  
  2531.      mg_get  Do magic after a value is retrieved from the SV.  See sv_magic.
  2532.  
  2533.                      int     mg_get _((SV* sv));
  2534.  
  2535.  
  2536.      mg_len  Report on the SV's length.  See sv_magic.
  2537.  
  2538.                      U32     mg_len _((SV* sv));
  2539.  
  2540.  
  2541.      mg_magical
  2542.              Turns on the magical status of an SV.  See sv_magic.
  2543.  
  2544.                      void    mg_magical _((SV* sv));
  2545.  
  2546.  
  2547.      mg_set  Do magic after a value is assigned to the SV.  See sv_magic.
  2548.  
  2549.                      int     mg_set _((SV* sv));
  2550.  
  2551.  
  2552.      Move    The XSUB-writer's interface to the C memmove function.  The s is
  2553.              the source, d is the destination, n is the number of items, and t
  2554.              is the type.  Can do overlapping moves.  See also Copy.
  2555.  
  2556.                      (void) Move( s, d, n, t );
  2557.  
  2558.  
  2559.      na      A variable which may be used with SvPV to tell Perl to calculate
  2560.              the string length.
  2561.  
  2562.      New     The XSUB-writer's interface to the C malloc function.
  2563.  
  2564.                      void * New( x, void *ptr, int size, type )
  2565.  
  2566.  
  2567.  
  2568.  
  2569.  
  2570.  
  2571.                                                                        PPPPaaaaggggeeee 33339999
  2572.  
  2573.  
  2574.  
  2575.  
  2576.  
  2577.  
  2578. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  2579.  
  2580.  
  2581.  
  2582.      Newc    The XSUB-writer's interface to the C malloc function, with cast.
  2583.  
  2584.                      void * Newc( x, void *ptr, int size, type, cast )
  2585.  
  2586.  
  2587.      Newz    The XSUB-writer's interface to the C malloc function.  The
  2588.              allocated memory is zeroed with memzero.
  2589.  
  2590.                      void * Newz( x, void *ptr, int size, type )
  2591.  
  2592.  
  2593.      newAV   Creates a new AV.  The reference count is set to 1.
  2594.  
  2595.                      AV*     newAV _((void));
  2596.  
  2597.  
  2598.      newHV   Creates a new HV.  The reference count is set to 1.
  2599.  
  2600.                      HV*     newHV _((void));
  2601.  
  2602.  
  2603.      newRV_inc
  2604.              Creates an RV wrapper for an SV.  The reference count for the
  2605.              original SV is incremented.
  2606.  
  2607.                      SV*     newRV_inc _((SV* ref));
  2608.  
  2609.              For historical reasons, "newRV" is a synonym for "newRV_inc".
  2610.  
  2611.      newRV_noinc
  2612.              Creates an RV wrapper for an SV.  The reference count for the
  2613.              original SV is nnnnooootttt incremented.
  2614.  
  2615.                      SV*     newRV_noinc _((SV* ref));
  2616.  
  2617.  
  2618.      newSV   Creates a new SV.  The len parameter indicates the number of
  2619.              bytes of preallocated string space the SV should have.  The
  2620.              reference count for the new SV is set to 1.
  2621.  
  2622.                      SV*     newSV _((STRLEN len));
  2623.  
  2624.  
  2625.      newSViv Creates a new SV and copies an integer into it.  The reference
  2626.              count for the SV is set to 1.
  2627.  
  2628.                      SV*     newSViv _((IV i));
  2629.  
  2630.  
  2631.      newSVnv Creates a new SV and copies a double into it.  The reference
  2632.              count for the SV is set to 1.
  2633.  
  2634.  
  2635.  
  2636.  
  2637.                                                                        PPPPaaaaggggeeee 44440000
  2638.  
  2639.  
  2640.  
  2641.  
  2642.  
  2643.  
  2644. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  2645.  
  2646.  
  2647.  
  2648.                      SV*     newSVnv _((NV i));
  2649.  
  2650.  
  2651.      newSVpv Creates a new SV and copies a string into it.  The reference
  2652.              count for the SV is set to 1.  If len is zero then Perl will
  2653.              compute the length.
  2654.  
  2655.                      SV*     newSVpv _((char* s, STRLEN len));
  2656.  
  2657.  
  2658.      newSVrv Creates a new SV for the RV, rv, to point to.  If rv is not an RV
  2659.              then it will be upgraded to one.  If classname is non-null then
  2660.              the new SV will be blessed in the specified package.  The new SV
  2661.              is returned and its reference count is 1.
  2662.  
  2663.                      SV*     newSVrv _((SV* rv, char* classname));
  2664.  
  2665.  
  2666.      newSVsv Creates a new SV which is an exact duplicate of the original SV.
  2667.  
  2668.                      SV*     newSVsv _((SV* old));
  2669.  
  2670.  
  2671.      newXS   Used by xsubpp to hook up XSUBs as Perl subs.
  2672.  
  2673.      newXSproto
  2674.              Used by xsubpp to hook up XSUBs as Perl subs.  Adds Perl
  2675.              prototypes to the subs.
  2676.  
  2677.      Nullav  Null AV pointer.
  2678.  
  2679.      Nullch  Null character pointer.
  2680.  
  2681.      Nullcv  Null CV pointer.
  2682.  
  2683.      Nullhv  Null HV pointer.
  2684.  
  2685.      Nullsv  Null SV pointer.
  2686.  
  2687.      ORIGMARK
  2688.              The original stack mark for the XSUB.  See dORIGMARK.
  2689.  
  2690.      perl_alloc
  2691.              Allocates a new Perl interpreter.  See the _p_e_r_l_e_m_b_e_d manpage.
  2692.  
  2693.      perl_call_argv
  2694.              Performs a callback to the specified Perl sub.  See the _p_e_r_l_c_a_l_l
  2695.              manpage.
  2696.  
  2697.                      I32     perl_call_argv _((char* subname, I32 flags, char** argv));
  2698.  
  2699.  
  2700.  
  2701.  
  2702.  
  2703.                                                                        PPPPaaaaggggeeee 44441111
  2704.  
  2705.  
  2706.  
  2707.  
  2708.  
  2709.  
  2710. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  2711.  
  2712.  
  2713.  
  2714.      perl_call_method
  2715.              Performs a callback to the specified Perl method.  The blessed
  2716.              object must be on the stack.  See the _p_e_r_l_c_a_l_l manpage.
  2717.  
  2718.                      I32     perl_call_method _((char* methname, I32 flags));
  2719.  
  2720.  
  2721.      perl_call_pv
  2722.              Performs a callback to the specified Perl sub.  See the _p_e_r_l_c_a_l_l
  2723.              manpage.
  2724.  
  2725.                      I32     perl_call_pv _((char* subname, I32 flags));
  2726.  
  2727.  
  2728.      perl_call_sv
  2729.              Performs a callback to the Perl sub whose name is in the SV.  See
  2730.              the _p_e_r_l_c_a_l_l manpage.
  2731.  
  2732.                      I32     perl_call_sv _((SV* sv, I32 flags));
  2733.  
  2734.  
  2735.      perl_construct
  2736.              Initializes a new Perl interpreter.  See the _p_e_r_l_e_m_b_e_d manpage.
  2737.  
  2738.      perl_destruct
  2739.              Shuts down a Perl interpreter.  See the _p_e_r_l_e_m_b_e_d manpage.
  2740.  
  2741.      perl_eval_sv
  2742.              Tells Perl to eval the string in the SV.
  2743.  
  2744.                      I32     perl_eval_sv _((SV* sv, I32 flags));
  2745.  
  2746.  
  2747.      perl_eval_pv
  2748.              Tells Perl to eval the given string and return an SV* result.
  2749.  
  2750.                      SV*     perl_eval_pv _((char* p, I32 croak_on_error));
  2751.  
  2752.  
  2753.      perl_free
  2754.              Releases a Perl interpreter.  See the _p_e_r_l_e_m_b_e_d manpage.
  2755.  
  2756.      perl_get_av
  2757.              Returns the AV of the specified Perl array.  If create is set and
  2758.              the Perl variable does not exist then it will be created.  If
  2759.              create is not set and the variable does not exist then NULL is
  2760.              returned.
  2761.  
  2762.                      AV*     perl_get_av _((char* name, I32 create));
  2763.  
  2764.  
  2765.  
  2766.  
  2767.  
  2768.  
  2769.                                                                        PPPPaaaaggggeeee 44442222
  2770.  
  2771.  
  2772.  
  2773.  
  2774.  
  2775.  
  2776. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  2777.  
  2778.  
  2779.  
  2780.      perl_get_cv
  2781.              Returns the CV of the specified Perl sub.  If create is set and
  2782.              the Perl variable does not exist then it will be created.  If
  2783.              create is not set and the variable does not exist then NULL is
  2784.              returned.
  2785.  
  2786.                      CV*     perl_get_cv _((char* name, I32 create));
  2787.  
  2788.  
  2789.      perl_get_hv
  2790.              Returns the HV of the specified Perl hash.  If create is set and
  2791.              the Perl variable does not exist then it will be created.  If
  2792.              create is not set and the variable does not exist then NULL is
  2793.              returned.
  2794.  
  2795.                      HV*     perl_get_hv _((char* name, I32 create));
  2796.  
  2797.  
  2798.      perl_get_sv
  2799.              Returns the SV of the specified Perl scalar.  If create is set
  2800.              and the Perl variable does not exist then it will be created.  If
  2801.              create is not set and the variable does not exist then NULL is
  2802.              returned.
  2803.  
  2804.                      SV*     perl_get_sv _((char* name, I32 create));
  2805.  
  2806.  
  2807.      perl_parse
  2808.              Tells a Perl interpreter to parse a Perl script.  See the
  2809.              _p_e_r_l_e_m_b_e_d manpage.
  2810.  
  2811.      perl_require_pv
  2812.              Tells Perl to require a module.
  2813.  
  2814.                      void    perl_require_pv _((char* pv));
  2815.  
  2816.  
  2817.      perl_run
  2818.              Tells a Perl interpreter to run.  See the _p_e_r_l_e_m_b_e_d manpage.
  2819.  
  2820.      POPi    Pops an integer off the stack.
  2821.  
  2822.                      int POPi();
  2823.  
  2824.  
  2825.      POPl    Pops a long off the stack.
  2826.  
  2827.                      long POPl();
  2828.  
  2829.  
  2830.  
  2831.  
  2832.  
  2833.  
  2834.  
  2835.                                                                        PPPPaaaaggggeeee 44443333
  2836.  
  2837.  
  2838.  
  2839.  
  2840.  
  2841.  
  2842. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  2843.  
  2844.  
  2845.  
  2846.      POPp    Pops a string off the stack.
  2847.  
  2848.                      char * POPp();
  2849.  
  2850.  
  2851.      POPn    Pops a double off the stack.
  2852.  
  2853.                      double POPn();
  2854.  
  2855.  
  2856.      POPs    Pops an SV off the stack.
  2857.  
  2858.                      SV* POPs();
  2859.  
  2860.  
  2861.      PUSHMARK
  2862.              Opening bracket for arguments on a callback.  See PUTBACK and the
  2863.              _p_e_r_l_c_a_l_l manpage.
  2864.  
  2865.                      PUSHMARK(p)
  2866.  
  2867.  
  2868.      PUSHi   Push an integer onto the stack.  The stack must have room for
  2869.              this element.  See XPUSHi.
  2870.  
  2871.                      PUSHi(int d)
  2872.  
  2873.  
  2874.      PUSHn   Push a double onto the stack.  The stack must have room for this
  2875.              element.  See XPUSHn.
  2876.  
  2877.                      PUSHn(double d)
  2878.  
  2879.  
  2880.      PUSHp   Push a string onto the stack.  The stack must have room for this
  2881.              element.  The len indicates the length of the string.  See
  2882.              XPUSHp.
  2883.  
  2884.                      PUSHp(char *c, int len )
  2885.  
  2886.  
  2887.      PUSHs   Push an SV onto the stack.  The stack must have room for this
  2888.              element.  See XPUSHs.
  2889.  
  2890.                      PUSHs(sv)
  2891.  
  2892.  
  2893.      PUTBACK Closing bracket for XSUB arguments.  This is usually handled by
  2894.              xsubpp.  See PUSHMARK and the _p_e_r_l_c_a_l_l manpage for other uses.
  2895.  
  2896.                      PUTBACK;
  2897.  
  2898.  
  2899.  
  2900.  
  2901.                                                                        PPPPaaaaggggeeee 44444444
  2902.  
  2903.  
  2904.  
  2905.  
  2906.  
  2907.  
  2908. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  2909.  
  2910.  
  2911.  
  2912.      Renew   The XSUB-writer's interface to the C realloc function.
  2913.  
  2914.                      void * Renew( void *ptr, int size, type )
  2915.  
  2916.  
  2917.      Renewc  The XSUB-writer's interface to the C realloc function, with cast.
  2918.  
  2919.                      void * Renewc( void *ptr, int size, type, cast )
  2920.  
  2921.  
  2922.      RETVAL  Variable which is setup by xsubpp to hold the return value for an
  2923.              XSUB.  This is always the proper type for the XSUB.  See the
  2924.              section on _T_h_e _R_E_T_V_A_L _V_a_r_i_a_b_l_e in the _p_e_r_l_x_s manpage.
  2925.  
  2926.      safefree
  2927.              The XSUB-writer's interface to the C free function.
  2928.  
  2929.      safemalloc
  2930.              The XSUB-writer's interface to the C malloc function.
  2931.  
  2932.      saferealloc
  2933.              The XSUB-writer's interface to the C realloc function.
  2934.  
  2935.      savepv  Copy a string to a safe spot.  This does not use an SV.
  2936.  
  2937.                      char*   savepv _((char* sv));
  2938.  
  2939.  
  2940.      savepvn Copy a string to a safe spot.  The len indicates number of bytes
  2941.              to copy.  This does not use an SV.
  2942.  
  2943.                      char*   savepvn _((char* sv, I32 len));
  2944.  
  2945.  
  2946.      SAVETMPS
  2947.              Opening bracket for temporaries on a callback.  See FREETMPS and
  2948.              the _p_e_r_l_c_a_l_l manpage.
  2949.  
  2950.                      SAVETMPS;
  2951.  
  2952.  
  2953.      SP      Stack pointer.  This is usually handled by xsubpp.  See dSP and
  2954.              SPAGAIN.
  2955.  
  2956.      SPAGAIN Refetch the stack pointer.  Used after a callback.  See the
  2957.              _p_e_r_l_c_a_l_l manpage.
  2958.  
  2959.                      SPAGAIN;
  2960.  
  2961.  
  2962.  
  2963.  
  2964.  
  2965.  
  2966.  
  2967.                                                                        PPPPaaaaggggeeee 44445555
  2968.  
  2969.  
  2970.  
  2971.  
  2972.  
  2973.  
  2974. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  2975.  
  2976.  
  2977.  
  2978.      ST      Used to access elements on the XSUB's stack.
  2979.  
  2980.                      SV* ST(int x)
  2981.  
  2982.  
  2983.      strEQ   Test two strings to see if they are equal.  Returns true or
  2984.              false.
  2985.  
  2986.                      int strEQ( char *s1, char *s2 )
  2987.  
  2988.  
  2989.      strGE   Test two strings to see if the first, s1, is greater than or
  2990.              equal to the second, s2.  Returns true or false.
  2991.  
  2992.                      int strGE( char *s1, char *s2 )
  2993.  
  2994.  
  2995.      strGT   Test two strings to see if the first, s1, is greater than the
  2996.              second, s2.  Returns true or false.
  2997.  
  2998.                      int strGT( char *s1, char *s2 )
  2999.  
  3000.  
  3001.      strLE   Test two strings to see if the first, s1, is less than or equal
  3002.              to the second, s2.  Returns true or false.
  3003.  
  3004.                      int strLE( char *s1, char *s2 )
  3005.  
  3006.  
  3007.      strLT   Test two strings to see if the first, s1, is less than the
  3008.              second, s2.  Returns true or false.
  3009.  
  3010.                      int strLT( char *s1, char *s2 )
  3011.  
  3012.  
  3013.      strNE   Test two strings to see if they are different.  Returns true or
  3014.              false.
  3015.  
  3016.                      int strNE( char *s1, char *s2 )
  3017.  
  3018.  
  3019.      strnEQ  Test two strings to see if they are equal.  The len parameter
  3020.              indicates the number of bytes to compare.  Returns true or false.
  3021.  
  3022.                      int strnEQ( char *s1, char *s2 )
  3023.  
  3024.  
  3025.      strnNE  Test two strings to see if they are different.  The len parameter
  3026.              indicates the number of bytes to compare.  Returns true or false.
  3027.  
  3028.                      int strnNE( char *s1, char *s2, int len )
  3029.  
  3030.  
  3031.  
  3032.  
  3033.                                                                        PPPPaaaaggggeeee 44446666
  3034.  
  3035.  
  3036.  
  3037.  
  3038.  
  3039.  
  3040. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  3041.  
  3042.  
  3043.  
  3044.      sv_2mortal
  3045.              Marks an SV as mortal.  The SV will be destroyed when the current
  3046.              context ends.
  3047.  
  3048.                      SV*     sv_2mortal _((SV* sv));
  3049.  
  3050.  
  3051.      sv_bless
  3052.              Blesses an SV into a specified package.  The SV must be an RV.
  3053.              The package must be designated by its stash (see gv_stashpv()).
  3054.              The reference count of the SV is unaffected.
  3055.  
  3056.                      SV*     sv_bless _((SV* sv, HV* stash));
  3057.  
  3058.  
  3059.      sv_catpv
  3060.              Concatenates the string onto the end of the string which is in
  3061.              the SV.
  3062.  
  3063.                      void    sv_catpv _((SV* sv, char* ptr));
  3064.  
  3065.  
  3066.      sv_catpvn
  3067.              Concatenates the string onto the end of the string which is in
  3068.              the SV.  The len indicates number of bytes to copy.
  3069.  
  3070.                      void    sv_catpvn _((SV* sv, char* ptr, STRLEN len));
  3071.  
  3072.  
  3073.      sv_catpvf
  3074.              Processes its arguments like sprintf and appends the formatted
  3075.              output to an SV.
  3076.  
  3077.                      void    sv_catpvf _((SV* sv, const char* pat, ...));
  3078.  
  3079.  
  3080.      sv_catsv
  3081.              Concatenates the string from SV ssv onto the end of the string in
  3082.              SV dsv.
  3083.  
  3084.                      void    sv_catsv _((SV* dsv, SV* ssv));
  3085.  
  3086.  
  3087.      sv_cmp  Compares the strings in two SVs.  Returns -1, 0, or 1 indicating
  3088.              whether the string in sv1 is less than, equal to, or greater than
  3089.              the string in sv2.
  3090.  
  3091.                      I32     sv_cmp _((SV* sv1, SV* sv2));
  3092.  
  3093.  
  3094.  
  3095.  
  3096.  
  3097.  
  3098.  
  3099.                                                                        PPPPaaaaggggeeee 44447777
  3100.  
  3101.  
  3102.  
  3103.  
  3104.  
  3105.  
  3106. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  3107.  
  3108.  
  3109.  
  3110.      SvCUR   Returns the length of the string which is in the SV.  See SvLEN.
  3111.  
  3112.                      int SvCUR (SV* sv)
  3113.  
  3114.  
  3115.      SvCUR_set
  3116.              Set the length of the string which is in the SV.  See SvCUR.
  3117.  
  3118.                      SvCUR_set (SV* sv, int val )
  3119.  
  3120.  
  3121.      sv_dec  Auto-decrement of the value in the SV.
  3122.  
  3123.                      void    sv_dec _((SV* sv));
  3124.  
  3125.  
  3126.      SvEND   Returns a pointer to the last character in the string which is in
  3127.              the SV.  See SvCUR.  Access the character as
  3128.  
  3129.                      *SvEND(sv)
  3130.  
  3131.  
  3132.      sv_eq   Returns a boolean indicating whether the strings in the two SVs
  3133.              are identical.
  3134.  
  3135.                      I32     sv_eq _((SV* sv1, SV* sv2));
  3136.  
  3137.  
  3138.      SvGROW  Expands the character buffer in the SV.  Calls sv_grow to perform
  3139.              the expansion if necessary.  Returns a pointer to the character
  3140.              buffer.
  3141.  
  3142.                      char * SvGROW( SV* sv, int len )
  3143.  
  3144.  
  3145.      sv_grow Expands the character buffer in the SV.  This will use sv_unref
  3146.              and will upgrade the SV to SVt_PV.  Returns a pointer to the
  3147.              character buffer.  Use SvGROW.
  3148.  
  3149.      sv_inc  Auto-increment of the value in the SV.
  3150.  
  3151.                      void    sv_inc _((SV* sv));
  3152.  
  3153.  
  3154.      SvIOK   Returns a boolean indicating whether the SV contains an integer.
  3155.  
  3156.                      int SvIOK (SV* SV)
  3157.  
  3158.  
  3159.      SvIOK_off
  3160.              Unsets the IV status of an SV.
  3161.  
  3162.  
  3163.  
  3164.  
  3165.                                                                        PPPPaaaaggggeeee 44448888
  3166.  
  3167.  
  3168.  
  3169.  
  3170.  
  3171.  
  3172. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  3173.  
  3174.  
  3175.  
  3176.                      SvIOK_off (SV* sv)
  3177.  
  3178.  
  3179.      SvIOK_on
  3180.              Tells an SV that it is an integer.
  3181.  
  3182.                      SvIOK_on (SV* sv)
  3183.  
  3184.  
  3185.      SvIOK_only
  3186.              Tells an SV that it is an integer and disables all other OK bits.
  3187.  
  3188.                      SvIOK_on (SV* sv)
  3189.  
  3190.  
  3191.      SvIOKp  Returns a boolean indicating whether the SV contains an integer.
  3192.              Checks the pppprrrriiiivvvvaaaatttteeee setting.  Use SvIOK.
  3193.  
  3194.                      int SvIOKp (SV* SV)
  3195.  
  3196.  
  3197.      sv_isa  Returns a boolean indicating whether the SV is blessed into the
  3198.              specified class.  This does not know how to check for subtype, so
  3199.              it doesn't work in an inheritance relationship.
  3200.  
  3201.                      int     sv_isa _((SV* sv, char* name));
  3202.  
  3203.  
  3204.      SvIV    Returns the integer which is in the SV.
  3205.  
  3206.                      int SvIV (SV* sv)
  3207.  
  3208.  
  3209.      sv_isobject
  3210.              Returns a boolean indicating whether the SV is an RV pointing to
  3211.              a blessed object.  If the SV is not an RV, or if the object is
  3212.              not blessed, then this will return false.
  3213.  
  3214.                      int     sv_isobject _((SV* sv));
  3215.  
  3216.  
  3217.      SvIVX   Returns the integer which is stored in the SV.
  3218.  
  3219.                      int  SvIVX (SV* sv);
  3220.  
  3221.  
  3222.      SvLEN   Returns the size of the string buffer in the SV.  See SvCUR.
  3223.  
  3224.                      int SvLEN (SV* sv)
  3225.  
  3226.  
  3227.  
  3228.  
  3229.  
  3230.  
  3231.                                                                        PPPPaaaaggggeeee 44449999
  3232.  
  3233.  
  3234.  
  3235.  
  3236.  
  3237.  
  3238. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  3239.  
  3240.  
  3241.  
  3242.      sv_len  Returns the length of the string in the SV.  Use SvCUR.
  3243.  
  3244.                      STRLEN  sv_len _((SV* sv));
  3245.  
  3246.  
  3247.      sv_magic
  3248.              Adds magic to an SV.
  3249.  
  3250.                      void    sv_magic _((SV* sv, SV* obj, int how, char* name, I32 namlen));
  3251.  
  3252.  
  3253.      sv_mortalcopy
  3254.              Creates a new SV which is a copy of the original SV.  The new SV
  3255.              is marked as mortal.
  3256.  
  3257.                      SV*     sv_mortalcopy _((SV* oldsv));
  3258.  
  3259.  
  3260.      SvOK    Returns a boolean indicating whether the value is an SV.
  3261.  
  3262.                      int SvOK (SV* sv)
  3263.  
  3264.  
  3265.      sv_newmortal
  3266.              Creates a new SV which is mortal.  The reference count of the SV
  3267.              is set to 1.
  3268.  
  3269.                      SV*     sv_newmortal _((void));
  3270.  
  3271.  
  3272.      sv_no   This is the false SV.  See sv_yes.  Always refer to this as
  3273.              &sv_no.
  3274.  
  3275.      SvNIOK  Returns a boolean indicating whether the SV contains a number,
  3276.              integer or double.
  3277.  
  3278.                      int SvNIOK (SV* SV)
  3279.  
  3280.  
  3281.      SvNIOK_off
  3282.              Unsets the NV/IV status of an SV.
  3283.  
  3284.                      SvNIOK_off (SV* sv)
  3285.  
  3286.  
  3287.      SvNIOKp Returns a boolean indicating whether the SV contains a number,
  3288.              integer or double.  Checks the pppprrrriiiivvvvaaaatttteeee setting.  Use SvNIOK.
  3289.  
  3290.                      int SvNIOKp (SV* SV)
  3291.  
  3292.  
  3293.  
  3294.  
  3295.  
  3296.  
  3297.                                                                        PPPPaaaaggggeeee 55550000
  3298.  
  3299.  
  3300.  
  3301.  
  3302.  
  3303.  
  3304. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  3305.  
  3306.  
  3307.  
  3308.      SvNOK   Returns a boolean indicating whether the SV contains a double.
  3309.  
  3310.                      int SvNOK (SV* SV)
  3311.  
  3312.  
  3313.      SvNOK_off
  3314.              Unsets the NV status of an SV.
  3315.  
  3316.                      SvNOK_off (SV* sv)
  3317.  
  3318.  
  3319.      SvNOK_on
  3320.              Tells an SV that it is a double.
  3321.  
  3322.                      SvNOK_on (SV* sv)
  3323.  
  3324.  
  3325.      SvNOK_only
  3326.              Tells an SV that it is a double and disables all other OK bits.
  3327.  
  3328.                      SvNOK_on (SV* sv)
  3329.  
  3330.  
  3331.      SvNOKp  Returns a boolean indicating whether the SV contains a double.
  3332.              Checks the pppprrrriiiivvvvaaaatttteeee setting.  Use SvNOK.
  3333.  
  3334.                      int SvNOKp (SV* SV)
  3335.  
  3336.  
  3337.      SvNV    Returns the double which is stored in the SV.
  3338.  
  3339.                      double SvNV (SV* sv);
  3340.  
  3341.  
  3342.      SvNVX   Returns the double which is stored in the SV.
  3343.  
  3344.                      double SvNVX (SV* sv);
  3345.  
  3346.  
  3347.      SvPOK   Returns a boolean indicating whether the SV contains a character
  3348.              string.
  3349.  
  3350.                      int SvPOK (SV* SV)
  3351.  
  3352.  
  3353.      SvPOK_off
  3354.              Unsets the PV status of an SV.
  3355.  
  3356.                      SvPOK_off (SV* sv)
  3357.  
  3358.  
  3359.  
  3360.  
  3361.  
  3362.  
  3363.                                                                        PPPPaaaaggggeeee 55551111
  3364.  
  3365.  
  3366.  
  3367.  
  3368.  
  3369.  
  3370. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  3371.  
  3372.  
  3373.  
  3374.      SvPOK_on
  3375.              Tells an SV that it is a string.
  3376.  
  3377.                      SvPOK_on (SV* sv)
  3378.  
  3379.  
  3380.      SvPOK_only
  3381.              Tells an SV that it is a string and disables all other OK bits.
  3382.  
  3383.                      SvPOK_on (SV* sv)
  3384.  
  3385.  
  3386.      SvPOKp  Returns a boolean indicating whether the SV contains a character
  3387.              string.  Checks the pppprrrriiiivvvvaaaatttteeee setting.  Use SvPOK.
  3388.  
  3389.                      int SvPOKp (SV* SV)
  3390.  
  3391.  
  3392.      SvPV    Returns a pointer to the string in the SV, or a stringified form
  3393.              of the SV if the SV does not contain a string.  If len is na then
  3394.              Perl will handle the length on its own.
  3395.  
  3396.                      char * SvPV (SV* sv, int len )
  3397.  
  3398.  
  3399.      SvPVX   Returns a pointer to the string in the SV.  The SV must contain a
  3400.              string.
  3401.  
  3402.                      char * SvPVX (SV* sv)
  3403.  
  3404.  
  3405.      SvREFCNT
  3406.              Returns the value of the object's reference count.
  3407.  
  3408.                      int SvREFCNT (SV* sv);
  3409.  
  3410.  
  3411.      SvREFCNT_dec
  3412.              Decrements the reference count of the given SV.
  3413.  
  3414.                      void SvREFCNT_dec (SV* sv)
  3415.  
  3416.  
  3417.      SvREFCNT_inc
  3418.              Increments the reference count of the given SV.
  3419.  
  3420.                      void SvREFCNT_inc (SV* sv)
  3421.  
  3422.  
  3423.      SvROK   Tests if the SV is an RV.
  3424.  
  3425.                      int SvROK (SV* sv)
  3426.  
  3427.  
  3428.  
  3429.                                                                        PPPPaaaaggggeeee 55552222
  3430.  
  3431.  
  3432.  
  3433.  
  3434.  
  3435.  
  3436. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  3437.  
  3438.  
  3439.  
  3440.      SvROK_off
  3441.              Unsets the RV status of an SV.
  3442.  
  3443.                      SvROK_off (SV* sv)
  3444.  
  3445.  
  3446.      SvROK_on
  3447.              Tells an SV that it is an RV.
  3448.  
  3449.                      SvROK_on (SV* sv)
  3450.  
  3451.  
  3452.      SvRV    Dereferences an RV to return the SV.
  3453.  
  3454.                      SV*     SvRV (SV* sv);
  3455.  
  3456.  
  3457.      SvTAINT Taints an SV if tainting is enabled
  3458.  
  3459.                      SvTAINT (SV* sv);
  3460.  
  3461.  
  3462.      SvTAINTED
  3463.              Checks to see if an SV is tainted. Returns TRUE if it is, FALSE
  3464.              if not.
  3465.  
  3466.                      SvTAINTED (SV* sv);
  3467.  
  3468.  
  3469.      SvTAINTED_off
  3470.              Untaints an SV. Be _v_e_r_y careful with this routine, as it short-
  3471.              circuits some of Perl's fundamental security features. XS module
  3472.              authors should not use this function unless they fully understand
  3473.              all the implications of unconditionally untainting the value.
  3474.              Untainting should be done in the standard perl fashion, via a
  3475.              carefully crafted regexp, rather than directly untainting
  3476.              variables.
  3477.  
  3478.                      SvTAINTED_off (SV* sv);
  3479.  
  3480.  
  3481.      SvTAINTED_on
  3482.              Marks an SV as tainted.
  3483.  
  3484.                      SvTAINTED_on (SV* sv);
  3485.  
  3486.  
  3487.      sv_setiv
  3488.              Copies an integer into the given SV.
  3489.  
  3490.                      void    sv_setiv _((SV* sv, IV num));
  3491.  
  3492.  
  3493.  
  3494.  
  3495.                                                                        PPPPaaaaggggeeee 55553333
  3496.  
  3497.  
  3498.  
  3499.  
  3500.  
  3501.  
  3502. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  3503.  
  3504.  
  3505.  
  3506.      sv_setnv
  3507.              Copies a double into the given SV.
  3508.  
  3509.                      void    sv_setnv _((SV* sv, double num));
  3510.  
  3511.  
  3512.      sv_setpv
  3513.              Copies a string into an SV.  The string must be null-terminated.
  3514.  
  3515.                      void    sv_setpv _((SV* sv, char* ptr));
  3516.  
  3517.  
  3518.      sv_setpvn
  3519.              Copies a string into an SV.  The len parameter indicates the
  3520.              number of bytes to be copied.
  3521.  
  3522.                      void    sv_setpvn _((SV* sv, char* ptr, STRLEN len));
  3523.  
  3524.  
  3525.      sv_setpvf
  3526.              Processes its arguments like sprintf and sets an SV to the
  3527.              formatted output.
  3528.  
  3529.                      void    sv_setpvf _((SV* sv, const char* pat, ...));
  3530.  
  3531.  
  3532.      sv_setref_iv
  3533.              Copies an integer into a new SV, optionally blessing the SV.  The
  3534.              rv argument will be upgraded to an RV.  That RV will be modified
  3535.              to point to the new SV.  The classname argument indicates the
  3536.              package for the blessing.  Set classname to Nullch to avoid the
  3537.              blessing.  The new SV will be returned and will have a reference
  3538.              count of 1.
  3539.  
  3540.                      SV*     sv_setref_iv _((SV *rv, char *classname, IV iv));
  3541.  
  3542.  
  3543.      sv_setref_nv
  3544.              Copies a double into a new SV, optionally blessing the SV.  The
  3545.              rv argument will be upgraded to an RV.  That RV will be modified
  3546.              to point to the new SV.  The classname argument indicates the
  3547.              package for the blessing.  Set classname to Nullch to avoid the
  3548.              blessing.  The new SV will be returned and will have a reference
  3549.              count of 1.
  3550.  
  3551.                      SV*     sv_setref_nv _((SV *rv, char *classname, double nv));
  3552.  
  3553.  
  3554.      sv_setref_pv
  3555.              Copies a pointer into a new SV, optionally blessing the SV.  The
  3556.              rv argument will be upgraded to an RV.  That RV will be modified
  3557.              to point to the new SV.  If the pv argument is NULL then sv_undef
  3558.  
  3559.  
  3560.  
  3561.                                                                        PPPPaaaaggggeeee 55554444
  3562.  
  3563.  
  3564.  
  3565.  
  3566.  
  3567.  
  3568. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  3569.  
  3570.  
  3571.  
  3572.              will be placed into the SV.  The classname argument indicates the
  3573.              package for the blessing.  Set classname to Nullch to avoid the
  3574.              blessing.  The new SV will be returned and will have a reference
  3575.              count of 1.
  3576.  
  3577.                      SV*     sv_setref_pv _((SV *rv, char *classname, void* pv));
  3578.  
  3579.              Do not use with integral Perl types such as HV, AV, SV, CV,
  3580.              because those objects will become corrupted by the pointer copy
  3581.              process.
  3582.  
  3583.              Note that sv_setref_pvn copies the string while this copies the
  3584.              pointer.
  3585.  
  3586.      sv_setref_pvn
  3587.              Copies a string into a new SV, optionally blessing the SV.  The
  3588.              length of the string must be specified with n.  The rv argument
  3589.              will be upgraded to an RV.  That RV will be modified to point to
  3590.              the new SV.  The classname argument indicates the package for the
  3591.              blessing.  Set classname to Nullch to avoid the blessing.  The
  3592.              new SV will be returned and will have a reference count of 1.
  3593.  
  3594.                      SV*     sv_setref_pvn _((SV *rv, char *classname, char* pv, I32 n));
  3595.  
  3596.              Note that sv_setref_pv copies the pointer while this copies the
  3597.              string.
  3598.  
  3599.      sv_setsv
  3600.              Copies the contents of the source SV ssv into the destination SV
  3601.              dsv.  The source SV may be destroyed if it is mortal.
  3602.  
  3603.                      void    sv_setsv _((SV* dsv, SV* ssv));
  3604.  
  3605.  
  3606.      SvSTASH Returns the stash of the SV.
  3607.  
  3608.                      HV * SvSTASH (SV* sv)
  3609.  
  3610.  
  3611.      SVt_IV  Integer type flag for scalars.  See svtype.
  3612.  
  3613.      SVt_PV  Pointer type flag for scalars.  See svtype.
  3614.  
  3615.      SVt_PVAV
  3616.              Type flag for arrays.  See svtype.
  3617.  
  3618.      SVt_PVCV
  3619.              Type flag for code refs.  See svtype.
  3620.  
  3621.      SVt_PVHV
  3622.              Type flag for hashes.  See svtype.
  3623.  
  3624.  
  3625.  
  3626.  
  3627.                                                                        PPPPaaaaggggeeee 55555555
  3628.  
  3629.  
  3630.  
  3631.  
  3632.  
  3633.  
  3634. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  3635.  
  3636.  
  3637.  
  3638.      SVt_PVMG
  3639.              Type flag for blessed scalars.  See svtype.
  3640.  
  3641.      SVt_NV  Double type flag for scalars.  See svtype.
  3642.  
  3643.      SvTRUE  Returns a boolean indicating whether Perl would evaluate the SV
  3644.              as true or false, defined or undefined.
  3645.  
  3646.                      int SvTRUE (SV* sv)
  3647.  
  3648.  
  3649.      SvTYPE  Returns the type of the SV.  See svtype.
  3650.  
  3651.                      svtype  SvTYPE (SV* sv)
  3652.  
  3653.  
  3654.      svtype  An enum of flags for Perl types.  These are found in the file
  3655.              ssssvvvv....hhhh in the svtype enum.  Test these flags with the SvTYPE macro.
  3656.  
  3657.      SvUPGRADE
  3658.              Used to upgrade an SV to a more complex form.  Uses sv_upgrade to
  3659.              perform the upgrade if necessary.  See svtype.
  3660.  
  3661.                      bool    SvUPGRADE _((SV* sv, svtype mt));
  3662.  
  3663.  
  3664.      sv_upgrade
  3665.              Upgrade an SV to a more complex form.  Use SvUPGRADE.  See
  3666.              svtype.
  3667.  
  3668.      sv_undef
  3669.              This is the undef SV.  Always refer to this as &sv_undef.
  3670.  
  3671.      sv_unref
  3672.              Unsets the RV status of the SV, and decrements the reference
  3673.              count of whatever was being referenced by the RV.  This can
  3674.              almost be thought of as a reversal of newSVrv.  See SvROK_off.
  3675.  
  3676.                      void    sv_unref _((SV* sv));
  3677.  
  3678.  
  3679.      sv_usepvn
  3680.              Tells an SV to use ptr to find its string value.  Normally the
  3681.              string is stored inside the SV but sv_usepvn allows the SV to use
  3682.              an outside string.  The ptr should point to memory that was
  3683.              allocated by malloc.  The string length, len, must be supplied.
  3684.              This function will realloc the memory pointed to by ptr, so that
  3685.              pointer should not be freed or used by the programmer after
  3686.              giving it to sv_usepvn.
  3687.  
  3688.                      void    sv_usepvn _((SV* sv, char* ptr, STRLEN len));
  3689.  
  3690.  
  3691.  
  3692.  
  3693.                                                                        PPPPaaaaggggeeee 55556666
  3694.  
  3695.  
  3696.  
  3697.  
  3698.  
  3699.  
  3700. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  3701.  
  3702.  
  3703.  
  3704.      sv_yes  This is the true SV.  See sv_no.  Always refer to this as
  3705.              &sv_yes.
  3706.  
  3707.      THIS    Variable which is setup by xsubpp to designate the object in a
  3708.              C++ XSUB.  This is always the proper type for the C++ object.
  3709.              See CLASS and the section on _U_s_i_n_g _X_S _W_i_t_h _C++ in the _p_e_r_l_x_s
  3710.              manpage.
  3711.  
  3712.      toLOWER Converts the specified character to lowercase.
  3713.  
  3714.                      int toLOWER (char c)
  3715.  
  3716.  
  3717.      toUPPER Converts the specified character to uppercase.
  3718.  
  3719.                      int toUPPER (char c)
  3720.  
  3721.  
  3722.      warn    This is the XSUB-writer's interface to Perl's warn function.  Use
  3723.              this function the same way you use the C printf function.  See
  3724.              croak().
  3725.  
  3726.      XPUSHi  Push an integer onto the stack, extending the stack if necessary.
  3727.              See PUSHi.
  3728.  
  3729.                      XPUSHi(int d)
  3730.  
  3731.  
  3732.      XPUSHn  Push a double onto the stack, extending the stack if necessary.
  3733.              See PUSHn.
  3734.  
  3735.                      XPUSHn(double d)
  3736.  
  3737.  
  3738.      XPUSHp  Push a string onto the stack, extending the stack if necessary.
  3739.              The len indicates the length of the string.  See PUSHp.
  3740.  
  3741.                      XPUSHp(char *c, int len)
  3742.  
  3743.  
  3744.      XPUSHs  Push an SV onto the stack, extending the stack if necessary.  See
  3745.              PUSHs.
  3746.  
  3747.                      XPUSHs(sv)
  3748.  
  3749.  
  3750.      XS      Macro to declare an XSUB and its C parameter list.  This is
  3751.              handled by xsubpp.
  3752.  
  3753.      XSRETURN
  3754.              Return from XSUB, indicating number of items on the stack.  This
  3755.              is usually handled by xsubpp.
  3756.  
  3757.  
  3758.  
  3759.                                                                        PPPPaaaaggggeeee 55557777
  3760.  
  3761.  
  3762.  
  3763.  
  3764.  
  3765.  
  3766. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  3767.  
  3768.  
  3769.  
  3770.                      XSRETURN(int x);
  3771.  
  3772.  
  3773.      XSRETURN_EMPTY
  3774.              Return an empty list from an XSUB immediately.
  3775.  
  3776.                      XSRETURN_EMPTY;
  3777.  
  3778.  
  3779.      XSRETURN_IV
  3780.              Return an integer from an XSUB immediately.  Uses XST_mIV.
  3781.  
  3782.                      XSRETURN_IV(IV v);
  3783.  
  3784.  
  3785.      XSRETURN_NO
  3786.              Return &sv_no from an XSUB immediately.  Uses XST_mNO.
  3787.  
  3788.                      XSRETURN_NO;
  3789.  
  3790.  
  3791.      XSRETURN_NV
  3792.              Return an double from an XSUB immediately.  Uses XST_mNV.
  3793.  
  3794.                      XSRETURN_NV(NV v);
  3795.  
  3796.  
  3797.      XSRETURN_PV
  3798.              Return a copy of a string from an XSUB immediately.  Uses
  3799.              XST_mPV.
  3800.  
  3801.                      XSRETURN_PV(char *v);
  3802.  
  3803.  
  3804.      XSRETURN_UNDEF
  3805.              Return &sv_undef from an XSUB immediately.  Uses XST_mUNDEF.
  3806.  
  3807.                      XSRETURN_UNDEF;
  3808.  
  3809.  
  3810.      XSRETURN_YES
  3811.              Return &sv_yes from an XSUB immediately.  Uses XST_mYES.
  3812.  
  3813.                      XSRETURN_YES;
  3814.  
  3815.  
  3816.      XST_mIV Place an integer into the specified position i on the stack.  The
  3817.              value is stored in a new mortal SV.
  3818.  
  3819.                      XST_mIV( int i, IV v );
  3820.  
  3821.  
  3822.  
  3823.  
  3824.  
  3825.                                                                        PPPPaaaaggggeeee 55558888
  3826.  
  3827.  
  3828.  
  3829.  
  3830.  
  3831.  
  3832. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  3833.  
  3834.  
  3835.  
  3836.      XST_mNV Place a double into the specified position i on the stack.  The
  3837.              value is stored in a new mortal SV.
  3838.  
  3839.                      XST_mNV( int i, NV v );
  3840.  
  3841.  
  3842.      XST_mNO Place &sv_no into the specified position i on the stack.
  3843.  
  3844.                      XST_mNO( int i );
  3845.  
  3846.  
  3847.      XST_mPV Place a copy of a string into the specified position i on the
  3848.              stack.  The value is stored in a new mortal SV.
  3849.  
  3850.                      XST_mPV( int i, char *v );
  3851.  
  3852.  
  3853.      XST_mUNDEF
  3854.              Place &sv_undef into the specified position i on the stack.
  3855.  
  3856.                      XST_mUNDEF( int i );
  3857.  
  3858.  
  3859.      XST_mYES
  3860.              Place &sv_yes into the specified position i on the stack.
  3861.  
  3862.                      XST_mYES( int i );
  3863.  
  3864.  
  3865.      XS_VERSION
  3866.              The version identifier for an XS module.  This is usually handled
  3867.              automatically by ExtUtils::MakeMaker.  See XS_VERSION_BOOTCHECK.
  3868.  
  3869.      XS_VERSION_BOOTCHECK
  3870.              Macro to verify that a PM module's $VERSION variable matches the
  3871.              XS module's XS_VERSION variable.  This is usually handled
  3872.              automatically by xsubpp.  See the section on _T_h_e _V_E_R_S_I_O_N_C_H_E_C_K:
  3873.              _K_e_y_w_o_r_d in the _p_e_r_l_x_s manpage.
  3874.  
  3875.      Zero    The XSUB-writer's interface to the C memzero function.  The d is
  3876.              the destination, n is the number of items, and t is the type.
  3877.  
  3878.                      (void) Zero( d, n, t );
  3879.  
  3880.  
  3881. EEEEDDDDIIIITTTTOOOORRRR
  3882.      Jeff Okamoto <_o_k_a_m_o_t_o@_c_o_r_p._h_p._c_o_m>
  3883.  
  3884.      With lots of help and suggestions from Dean Roehrich, Malcolm Beattie,
  3885.      Andreas Koenig, Paul Hudson, Ilya Zakharevich, Paul Marquess, Neil
  3886.      Bowers, Matthew Green, Tim Bunce, Spider Boardman, Ulrich Pfeifer, and
  3887.      Stephen McCamant.
  3888.  
  3889.  
  3890.  
  3891.                                                                        PPPPaaaaggggeeee 55559999
  3892.  
  3893.  
  3894.  
  3895.  
  3896.  
  3897.  
  3898. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  3899.  
  3900.  
  3901.  
  3902.      API Listing by Dean Roehrich <_r_o_e_h_r_i_c_h@_c_r_a_y._c_o_m>.
  3903.  
  3904. DDDDAAAATTTTEEEE
  3905.      Version 31.8: 1997/5/17
  3906.  
  3907.  
  3908.  
  3909.  
  3910.  
  3911.  
  3912.  
  3913.  
  3914.  
  3915.  
  3916.  
  3917.  
  3918.  
  3919.  
  3920.  
  3921.  
  3922.  
  3923.  
  3924.  
  3925.  
  3926.  
  3927.  
  3928.  
  3929.  
  3930.  
  3931.  
  3932.  
  3933.  
  3934.  
  3935.  
  3936.  
  3937.  
  3938.  
  3939.  
  3940.  
  3941.  
  3942.  
  3943.  
  3944.  
  3945.  
  3946.  
  3947.  
  3948.  
  3949.  
  3950.  
  3951.  
  3952.  
  3953.  
  3954.  
  3955.  
  3956.  
  3957.                                                                        PPPPaaaaggggeeee 66660000
  3958.  
  3959.  
  3960.  
  3961.  
  3962.  
  3963.  
  3964. PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))                                                        PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  3965.  
  3966.  
  3967.  
  3968.  
  3969.  
  3970.  
  3971.  
  3972.  
  3973.  
  3974.  
  3975.  
  3976.  
  3977.  
  3978.  
  3979.  
  3980.  
  3981.  
  3982.  
  3983.  
  3984.  
  3985.  
  3986.  
  3987.  
  3988.  
  3989.  
  3990.  
  3991.  
  3992.  
  3993.  
  3994.  
  3995.  
  3996.  
  3997.  
  3998.  
  3999.  
  4000.  
  4001.  
  4002.  
  4003.  
  4004.  
  4005.  
  4006.  
  4007.  
  4008.  
  4009.  
  4010.  
  4011.  
  4012.  
  4013.  
  4014.  
  4015.  
  4016.  
  4017.  
  4018.  
  4019.  
  4020.                                                                        PPPPaaaaggggeeee 66661111
  4021.  
  4022.  
  4023.  
  4024.  
  4025.  
  4026.  
  4027.